In imperative programming, a "go to" statement is an unconditional jump instruction that changes the flow of control to the point of the program referenced by the "go to" statement.
Questions tagged [goto]
1057 questions
15
votes
1 answer
Batch file: GOTO in a FOR loop
I have a batch file with a FOR loop. In the loop I must wait for a process to end, for which I used IF and GOTO. The problem is the GOTO is breaking the loop. I tried to find other solutions but I didn't find anything. How can it be done?
@echo…

Leo92
- 724
- 4
- 16
- 29
15
votes
4 answers
How can I exit a batch file from within a function?
I have a simple function written to check for directories:
:direxist
if not exist %~1 (
echo %~1 could not be found, check to make sure your location is correct.
goto:end
) else (
echo %~1 is a real directory
goto:eof
)
:end…

Brad Conyers
- 1,161
- 4
- 15
- 24
14
votes
5 answers
What are the valid use cases of goto in PHP?
I know, there are other questions about the goto statement introduced in PHP 5.3.
But I couldn't find any decent answer in there, all were of the type "last resort", "xkcd", "evil", "bad", "EVIL!!!". But no valid example. Only statements that there…

NikiC
- 100,734
- 37
- 191
- 225
14
votes
2 answers
Using goto to jump to inner or sibling scope
Is it allowed to jump to a label that's inside an inner scope or a sibling scope? If so, is it allowed to use variables declared in that scope?
Consider this code:
int cond(void);
void use(int);
void foo()
{
{
int y = 2;
…

Spike
- 725
- 5
- 12
14
votes
5 answers
Sql - goto statement
Is it good practice to use 'goto' statements in SQL queries?

SoftwareGeek
- 15,234
- 19
- 61
- 78
14
votes
6 answers
Why can't I add a goto label at the end of a method?
After researching a way to exit a nested loop, I decided to try using goto,
private void example()
{
for (int i = 0; i < 100; i++)
{
for (int ii = 0; ii < 100; ii++)
{
for (int iii = 0; iii < 100; iii++)
…

Sam
- 7,252
- 16
- 46
- 65
14
votes
10 answers
Will using goto cause memory leaks?
I have a program in which i need to break out of a large bunch of nested for loops. So far, the way most people have been telling me to do it is to use an ugly goto in my code.
Now, if i create a bunch of local stack (i think that's what they are…

Faken
- 11,352
- 17
- 59
- 74
13
votes
7 answers
C/C++: goto into the for loop
I have a bit unusual situation - I want to use goto statement to jump into the loop, not to jump out from it.
There are strong reasons to do so - this code must be part of some function which makes some calculations after the first call, returns…

Sergey
- 131
- 1
- 1
- 4
13
votes
1 answer
How to speed up dynamic dispatch by 20% using computed gotos in standard C++
Before you down-vote or start saying that gotoing is evil and obsolete, please read the justification of why it is viable in this case. Before you mark it as duplicate, please read the full question.
I was reading about virtual machine interpreters,…
user11313931
13
votes
3 answers
Explanation of switch statement constraints on variably modified types in C standard
I'm writing a C compiler, and when I come to the implementation of the switch statement one constraint confused me a lot. Section 6.8.4.2p2 of the standard states:
If a switch statement has an associated case or default label within
the scope of…
user2269707
13
votes
1 answer
What is an indirect goto statement?
In Clang API, there is a GotoStmt and an IndirectGotoStmt. There is very little explanation on the difference between these two kinds of goto statments. I know what a goto label; statement is. But what is an indirect goto statement? I want to know…

Galaxy
- 2,363
- 2
- 25
- 59
13
votes
1 answer
When jumping over a declaration, why is trivial destructor required?
goto or switch can jump over a declaration-statement given that it has no initializer and the construction is trivial — and that the object is also trivially destructible.
What's the rationale for the constraint on the destructor?
struct trivial {
…

Potatoswatter
- 134,909
- 25
- 265
- 421
12
votes
7 answers
How to (computed) goto and longjmp in C++?
I don't usually code C++, but a strange comp sci friend of mine got sick of looking at my wonderful FORTRAN programs and challenged me to rewrite one of them in C++, since he likes my C++ codes better. (We're betting money here.) Exact terms being…

Code Maker
- 145
- 1
- 6
12
votes
4 answers
In Perl, what is the right way for a subclass to alias a method in the base class?
I simply hate how CGI::Application's accessor for the CGI object is called query.
I would like my instance classes to be able to use an accessor named cgi to get the CGI object associated with the current instance of my CGI::Application…

Sinan Ünür
- 116,958
- 15
- 196
- 339
12
votes
8 answers
How to jump out of a C++ code block?
This is what I would like to do:
{
...
if(condition)
break;
...
}
This works for a loop. I would like something similar for a simple block of code.
Is it possible?
Am I forced to use a "goto"?
I think such an extension of the…

Pietro
- 12,086
- 26
- 100
- 193