goto

How can I rewrite this (cleanly) without gotos?

How can I do this cleanly without gotos? loop: if(condition1){ something(); } else if (condition2) { somethingDifferent(); } else { mostOfTheWork(); goto loop; } I'd prefer not to use breaks as well. Furthermore, it is expected to loop several (adv 40) times before doing something else, so the mostOfTheWork pa...

Language construct naming: Function/Goto

How is a language construct with the following properties called? It has a beginning and an end, just like a function It has a header containing it's name, also like a function but without arguments There can be any number of statements between its beginning and end, like a function You can use a function to jump to its beginning from ...

Should using Eval carry the same stigma as GoTo?

It is taught in every computer science class and written in many books that programmers should not use GoTo. There is even an xkcd comic about it. My question is have we reached a point where the same thing can be said about Eval? Where GoTo is not conductive for program flow and readability, Eval is the same for debugging, and program ...

Language Design: Combining Gotos and Functions

I'm designing and currently rethinking a low-level interpreted programming language with similarities to assembler. I very soon came across the functions/loops/gotos decision problem and thought that while loops like while and for would be too high-level and unfitting, gotos would be too low level, unmaintainable and generally evil agai...

GoTo statements and alternatives in VB.NET

I've posted a code snippet on another forum asking for help and people pointed out to me that using GoTo statements is very bad programming practice. I'm wondering: why is it bad? What alternatives to GoTo are there to use in VB.NET that would be considered generally more of a better practice? Consider this snippet below where the us...

c99 goto past initialization

While debugging a crash, I came across this issue in some code: int func() { char *p1 = malloc(...); if (p1 == NULL) goto err_exit; char *p2 = malloc(...); if (p2 == NULL) goto err_exit; ... err_exit: free(p2); free(p1); return -1; } The problem occurs when the first malloc fails. B...

Being pressured to GOTO the dark-side

We have a situation at work where developers working on a legacy (core) system are being pressured into using GOTO statements when adding new features into existing code that is already infected with spaghetti code. Now, I understand there may be arguments for using 'just one little GOTO' instead of spending the time on refactoring to a...

Handling EINTR (with goto?)

Background: This is a follow-up question to this thread about handling EINTR for system calls in C++ (Linux/GCC). Regardless of whether or not I intend to profile my application, it seems like I should be handling system calls setting errno to EINTR as a special case. There are many, many, many opinions about the use of goto. My quest...

What are the acceptable uses of goto?

Possible Duplicate: Examples of good gotos in C or C++ What uses of the goto statement do you consider acceptable? I am discussing some coding guidelines for C embedded work, and wondering if there are cases where goto is the cleanest way to do things. ...

Simple program logic to Call method continuously

Hi everybody, I am in a situation, in which my program needs to do processing and then wait for some interval, let's say 5 seconds and the do the same processing again. I don't know how to implement the logic. I have developed a logic, the code is below: private void ProcessEmail() { PprocessEmail:; //Do whatever ...

Sql - goto statement

Hi folks, is it good practise to use 'goto' statements in Sql queries? ...

Is GOTO really as evil as we are led to believe?

Possible Duplicates: GOTO still considered harmful? GoTo statements and alternatives in VB.NET I'm a young programmer, so all my working life I've been told GOTO is evil, don't use it, if you do, your first born son will die. Recently, I've realized that GOTO actually still exists in .NET and I was wondering, is GOTO really...

what programming languages support labels with break and continue statments ?

I recently read about labelled statments in java and the ability to specify a label with the break and continue statements. What other languages support this sort of syntax ? ...

Do Perl loop labels count as a GOTO?

Generally, it is good practice to avoid GOTOs. Keeping that in mind I've been having a debate with a coworker over this topic. Consider the following code: Line: while( <> ) { next Line if (insert logic); } Does using a loop label count as a goto? Here is what perlsyn in perldoc has to say: Here's how a C progra...

To use goto or not ?

Hello everyone. This question may sound cliched but I am in a situation here. I am trying to implement a finite state automaton to parse a certain string in C. As I started writing the code, I realised the code may be more readable if I used labels to mark the different states and use goto to jump from one state to another as the cas...

Goto out of a block: do destructors get called ?

Consider the following code: void foo() { { CSomeClass bar; // Some code here... goto label; // and here... } label: // and here... } Will the destructor of bar be called ? ...

Acceptable use of GoTo?

Hello all. I'm currently rewriting an old VB6 program in C# in the .Net Framework 2.0 (not my choice, it was decided by the company). For the most part, things have gone pretty well. The program measures incoming data from a precision grinding machine and displays graphs and dials to display the accuracy. The original programmer was a ...

Is this goto expressive?

The following code was a proof of concept for a message batching routine. Do I avoid goto like the plague and rewrite this code? Or do you think the goto is an expressive way to get this done? If you'd rewrite please post some code... var queue = new Queue<TraceItem>(this.batch); while (this.connected) { byte[] buffer = null; t...

Breaking a "for" loop using "break" considered harmful?

Possible Duplicate: Break statements In the real world Some days ago I started a quick open source project and, when some mates looked at the code on svn, one of them told me that using break statement inside a for loop is considered harmful and shouldn't be done. He added, though, that I would find several cases of break st...

Difference between GOTO and THROW?

Many people accused me recently for just mentioning a single word - "goto". It makes me wonder, why it is considered such a nasty word. I am aware of several previous discussions on the topic, but it doesn't convince me - some of the answers just says "it's bad" not even trying to explain and some bring reasons, irrelevant for scripting ...