0
0
Cprogramming~10 mins

Break statement in C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Break statement
Start Loop
Check Condition
Yes
Execute Loop Body
Check Break Condition
Break Loop
Exit Loop
End
The loop runs checking a condition each time. Inside, if the break condition is true, the loop stops immediately and exits.
Execution Sample
C
for (int i = 0; i < 5; i++) {
    if (i == 3) {
        break;
    }
    printf("%d ", i);
}
This loop prints numbers from 0 up to 2, then stops when i equals 3 because of the break.
Execution Table
IterationiCondition i<5Break Condition i==3ActionOutput
10TrueFalsePrint 00
21TrueFalsePrint 11
32TrueFalsePrint 22
43TrueTrueBreak loop
-3N/A-Exit loop-
💡 Loop exits at iteration 4 because break condition i==3 is True
Variable Tracker
VariableStartAfter 1After 2After 3Final
i0 (init)1233 (break)
Key Moments - 2 Insights
Why does the loop stop printing when i reaches 3?
Because at iteration 4 in the execution_table, the break condition i==3 is True, so the break statement stops the loop immediately.
Does the loop check the condition i<5 after break?
No, once break is executed (iteration 4), the loop exits immediately without checking i<5 again, as shown in the exit_note.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after iteration 3?
A"0 1 2 3 "
B"0 1 2 "
C"1 2 3 "
D"0 1 "
💡 Hint
Check the Output column for iteration 3 in the execution_table.
At which iteration does the break statement stop the loop?
AIteration 2
BIteration 3
CIteration 4
DIteration 5
💡 Hint
Look at the Break Condition and Action columns in the execution_table.
If the break condition was changed to i == 4, when would the loop stop?
AAfter printing 3
BAfter printing 2
CAfter printing 4
DIt would never stop early
💡 Hint
Think about when i equals 4 and how break works from the variable_tracker.
Concept Snapshot
Break statement in C:
- Used inside loops to stop loop immediately
- Syntax: break;
- When break runs, loop exits without checking further
- Useful to stop loop early based on condition
- After break, code continues after loop
Full Transcript
This visual trace shows how the break statement works in a C for loop. The loop starts with i=0 and runs while i<5. Each iteration prints i. When i reaches 3, the break condition becomes true, so the break statement stops the loop immediately. The loop does not continue to i=4 or 5. The variable i changes from 0 to 3, then stops. The output is numbers 0 1 2 printed with spaces. Key points: break stops loop instantly, no further iterations run after break, and the loop condition is not checked again after break.