Questions tagged [goto]
15 questions
108
votes
11 answers
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's cute to name his labels 'dengo' " See the…

Anon
- 3,565
- 3
- 27
- 45
66
votes
12 answers
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 language.
I recently heard some distaste for the…

Robz
- 1,613
- 4
- 13
- 10
47
votes
12 answers
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 - Eight.
public enum ExampleEnum {
One,
Two,…

Hazel へいぜる
- 1,165
- 1
- 8
- 19
41
votes
10 answers
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 need to check if is within a list of IPs and then…

php_nub_qq
- 2,204
- 4
- 17
- 25
34
votes
14 answers
Is using goto ever worthwhile?
goto is almost universally discouraged. Is using this statement ever worthwhile?

Casebash
- 7,662
- 5
- 41
- 62
31
votes
10 answers
Do we still have a case against the goto statement?
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 they make programs hard to understand." Press harder,…

fredoverflow
- 6,854
- 8
- 39
- 46
15
votes
7 answers
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 people to have to instruct the program to break out of a…

Panzercrisis
- 3,145
- 4
- 19
- 34
13
votes
7 answers
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 necessary to continue any other checks. Thus continue…

Anon
- 3,565
- 3
- 27
- 45
8
votes
3 answers
Why was GOTO included in PHP 5?
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 behind this?
Did the PHP developers community asked…

Tulains Córdova
- 39,201
- 12
- 97
- 154
2
votes
3 answers
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 practice?

JavaProphet
- 185
- 1
- 5
1
vote
2 answers
Is goto to improve DRY-ness OK?
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 myfunc(...) {
err_struct error = { .error = false…

Marco Scannadinari
- 293
- 1
- 5
0
votes
3 answers
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 language that only allows goto statement to go down,…

Akavall
- 425
- 1
- 3
- 10
0
votes
6 answers
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 to use something a bit more distinctive for…

rwallace
- 1,198
- 11
- 19
-1
votes
3 answers
I just used a goto statement. Is this OK?
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) {
js_value = FunctionTemplate::New(isolate,…

tbodt
- 115
- 5
-1
votes
2 answers
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 function is mandatory, but a goto is considered bad. Often one…

user3824211
- 11