0
0
C++programming~10 mins

Jump statement overview in C++ - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Jump statement overview
Start Execution
Normal Code Runs
Jump Statement?
NoContinue Normal Execution
Yes
Jump to Target
Resume Execution at Target
End or Loop Back
The program runs normally until it hits a jump statement, then it jumps to a specific point and continues execution from there.
Execution Sample
C++
#include <iostream>
int main() {
  for(int i=0; i<5; i++) {
    if(i == 3) break;
    std::cout << i << " ";
  }
  return 0;
}
This code uses a break jump statement to exit the loop early when i equals 3.
Execution Table
IterationiCondition i<5If i==3?ActionOutput
10TrueFalsePrint 00
21TrueFalsePrint 11
32TrueFalsePrint 22
43TrueTrueBreak loop
--False-Exit loop-
💡 Loop breaks when i == 3, so it stops before printing 3.
Variable Tracker
VariableStartAfter 1After 2After 3Final
i01233
Key Moments - 3 Insights
Why does the loop stop printing numbers after 2?
Because at iteration 4, i equals 3, the condition 'if(i == 3)' is true, so the break statement runs and exits the loop early (see execution_table row 4).
Does the break statement skip just the current iteration or the whole loop?
The break statement exits the entire loop immediately, not just skipping one iteration. This is shown in the execution_table where after break, the loop ends.
What happens if the break condition never becomes true?
The loop runs all iterations normally, printing all values from 0 to 4, because the break is never triggered.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of i when the loop breaks?
A2
B4
C3
D5
💡 Hint
Check the row where 'Action' is 'Break loop' in the execution_table.
At which iteration does the condition 'i < 5' become false?
AIteration 5
BIt never becomes false because of break
CIteration 4
DIteration 3
💡 Hint
Look at the exit_note and the last row of execution_table.
If we remove the break statement, what will be the output after all iterations?
A0 1 2 3 4
B0 1 2
C3 4
DNo output
💡 Hint
Refer to the key_moments explanation about what happens if break never triggers.
Concept Snapshot
Jump statements like break, continue, and goto change normal flow.
Break exits loops immediately.
Continue skips current iteration.
Goto jumps to a labeled statement.
Use jump statements carefully to avoid confusion.
Full Transcript
This example shows how a break jump statement works in a loop. The loop runs from i=0 to i=4 normally. When i reaches 3, the if condition triggers the break statement. This causes the loop to exit immediately, so numbers 3 and 4 are not printed. The execution table tracks each iteration, showing variable i, conditions, actions, and output. The variable tracker shows how i changes each step. Key moments clarify common confusions about break behavior. The quiz tests understanding of when the loop stops and what output is produced. The snapshot summarizes jump statements and their effects on program flow.