C goto Keyword
Example
Use goto to skip a line of code:
int myNum = 5;
if (myNum > 3) {
goto end;
}
printf("This line is skipped\n");
end:
printf("Done");
Definition and Usage
The goto keyword makes the program jump to a label. A label is a name followed by a colon, like end:, in front of a line of code. The program continues from the label.
The label must be in the same function as the goto statement. It can be before or after it.
Use goto only in rare cases, because it makes code hard to follow. A loop, break or an if statement is almost always a better choice.
Related Pages
Read more about jumping out of loops in our C Break and Continue Tutorial.