continue and break both bail out of something — but out of what, exactly? Mixing them up changes a loop that skips one item into a loop that abandons everything. This question from our C Programming Quiz App pins down what continue skips, what it doesn’t, and the one loop where it behaves differently than you’d guess.
The Quiz Question
int i;
for (i = 0; i < 3; i++) {
if (i == 1) continue;
printf("%d ", i);
}
What is printed by this code?
- 0 1 2
- 0 2
- 1
- 0 1
The Correct Answer: 0 2
continue abandons the rest of the current iteration and jumps to the loop’s next step — in a for loop, that means the increment i++ runs, then the condition is re-tested. So when i is 1, the printf is skipped but the loop marches on to 2. Verified on gcc 13.3 and Apple clang 21, clean under -ansi -Wall -Wextra:
$ gcc -ansi -Wall -Wextra cont.c && ./a.out 0 2
Why Each Wrong Answer Is Wrong
Why not “0 1 2”?
That would mean continue did nothing. But when i == 1 the continue executes and control never reaches the printf in that iteration — the 1 is genuinely skipped.
Why not “0 1”?
This is the break reading — as if hitting i == 1 ended the loop. (Even then the guess is off: break at i == 1 fires before printing 1, so the output would be just 0 — we ran it.) continue skips one lap; break leaves the track:
if (i == 1) continue; → 0 2 if (i == 1) break; → 0
Why not “1”?
This inverts the condition — as if continue meant “only process this one”. The if guards the skip, not the print: iterations 0 and 2 sail past the if and print normally; only iteration 1 takes the early exit.
Where continue Jumps — the for vs while Difference
In a for loop, continue jumps to the increment expression, then the test. That’s what keeps this loop finite. But translate the same logic to a while loop naively and the increment is part of the body — which continue skips:
i = 0;
while (i < 3) {
if (i == 1) continue; /* skips the i++ below — infinite loop! */
printf("%d ", i);
i++;
}
When i reaches 1, continue jumps straight back to the test with i still 1 — forever. This asymmetry is the practical reason the for form is preferred whenever an index drives the loop: the increment is structurally guaranteed to run, continue or not. The idiomatic use of continue is the early-skip guard at the top of a body — if (!valid(item)) continue; — which keeps the main logic un-indented; deep inside nested logic it gets harder to trace, same as its cousin break in a switch.
Frequently Asked Questions
What is the difference between continue and break in C?
continue skips the rest of the current iteration and proceeds with the next one; break terminates the whole loop immediately. In this example they produce 0 2 and 0 respectively.
Does continue skip the increment in a for loop?
No — in a for loop, continue jumps to the increment expression, then the condition. In a while loop, however, an increment written inside the body is skipped, which easily creates an infinite loop.
Can continue be used outside a loop?
No. continue is only valid inside for, while, or do-while bodies — and unlike break, it has no meaning in a switch. Anywhere else it’s a compile error.
Related Reading
- Switch Fallthrough in C – What Happens Without break
- Post-Increment in a while Condition – Why It Prints 1 2 3
- Ternary Operator in C
- C Aptitude Questions and Answers
Recommended Books
- The C Programming Language – Kernighan & Ritchie (India) | Amazon.com
- C Programming: A Modern Approach – K.N. King (India) | Amazon.com
This question is #98 in the C Programming Quiz App — 155 questions with explanations covering basics, operators, pointers, and more.
Download on Google Play →