Concept Flow - Goto statement overview
Start
Execute statements
Check for goto
Jump to label
End
The program runs statements in order, but when it hits a goto, it jumps to a labeled spot and continues from there.
int main() { int x = 0; if (x == 0) goto skip; x = 1; skip: return x; }
| Step | Line | Action | Variable x | Notes |
|---|---|---|---|---|
| 1 | int x = 0; | Initialize x to 0 | 0 | x set to 0 |
| 2 | if (x == 0) goto skip; | Check if x is 0 | 0 | Condition true, jump to label skip |
| 3 | skip: | Label reached | 0 | Jumped here, skip x=1 |
| 4 | return x; | Return x value | 0 | Function returns 0 |
| 5 | - | End of program | 0 | Program ends |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| x | undefined | 0 | 0 | 0 | 0 |
Goto statement overview in C: - Syntax: goto label; - Execution jumps to the label anywhere in the function - Labels end with a colon (label:) - Use carefully to avoid confusing flow - Skips normal sequential execution - Useful for simple jumps or error handling