Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [goto]

The tag has no usage guidance.

100
votes
11answers
18k views

What kind of bugs do “goto” statements lead to? Are there any historically significant examples?

I understand that save for breaking out of loops nested in loops; the goto statement is evaded and reviled as a bug prone style of programming, to never be used. Alt Text: "Neal Stephenson thinks it'...
29
votes
10answers
15k views

Do we still have a case against the goto statement? [duplicate]

Possible Duplicate: Is it ever worthwhile using goto? In a recent article, Andrew Koenig writes: When asked why goto statements are harmful, most programmers will say something like "because ...
45
votes
12answers
19k views

Avoiding the `goto` voodoo?

I have a switch structure that has several cases to handle. The switch operates over an enum which poses the issue of duplicate code through combined values: // All possible combinations of One - ...
8
votes
7answers
3k views

Best practice to “continue” from inside a nested loop?

Here is a simplified sample. Basically, it does checks on a string from a string list. If the check passes, it will remove that string (filterStringOut(i);), and it is no longer ...
58
votes
12answers
22k views

Is this a decent use-case for goto in C?

I really hesitate to ask this, because I don't want to "solicit debate, arguments, polling, or extended discussion" but I'm new to C and want to gain more insight into common patterns used in the ...
-1
votes
3answers
346 views

I just used a goto statement. Is this OK? [closed]

I just wrote this code that uses a goto statement. if (PyMethod_Check(attrib_value)) { PyObject *im_self = PyObject_GetAttrString(attrib_value, "im_self"); if (im_self == Py_None) { ...
-1
votes
2answers
240 views

Single exit of function uses goto

Apropos of What kind of bugs do "goto" statements lead to? Are there any historically significant examples? I am not that learned in C, and to me the puzzle is that a single exit of a ...
39
votes
10answers
13k views

What is so bad with goto when it's used for these obvious and relevant cases?

I have always known that goto is something bad, locked in a basement somewhere never to be seen for good but I ran into a code example today that makes perfect sense to use goto. I have an IP where I ...
28
votes
12answers
14k views

Is using goto ever worthwhile?

goto is almost universally discouraged. Is using this statement ever worthwhile?
2
votes
3answers
2k views

Can you pass a label as an argument, and have the function return to it?

So I would like to be able to call a function like this: void func(1, 2, 3, (void*)label) // can return normal or to the labels //some code label: //different code Is it possible, and is it bad ...
1
vote
2answers
466 views

Are there languages that allow goto statement to only go down?

goto statements can sometimes be useful to go down (to lower lines of code) in code, but can create a mess if used to go up (to higher lines of code). Therefore, I am wondering if there is any ...
1
vote
2answers
333 views

Is goto to improve DRY-ness OK? [duplicate]

My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this: err_struct ...
15
votes
7answers
2k views

Does this justify goto statements?

I came across this question a second ago, and I'm pulling some of the material off of there: Is there a name for the 'break n' construct? This appears to be a needlessly complex way for ...
8
votes
3answers
3k views

Why was GOTO included in PHP 5? [closed]

I discovered some time ago that the GOTO control keyword was introduced in PHP 5.3.0. http://php.net/manual/en/control-structures.goto.php Why did it happen? What are the language design goals ...
0
votes
6answers
2k views

Syntax for goto labels

In C, C++ and some dialects of BASIC, goto labels are declared with the syntax label:. I'm working on a language that uses name: type as the syntax for variable declarations, so I'd prefer if possible ...