continue skips the rest of the current iteration in a for, while, or do-while loop, then jumps to the next cycle. The loop keeps running—unlike break, which exits entirely.
Remember
continue; // skip rest of this iteration
in a for → still runs i++, then re-checks condition
in a while → jumps to condition (update counter first!)
not in switch → use break for cases
loop keeps going — only this pass is skipped
Place continue when the rest of this iteration should not run, but later ones should.
Write a loop as usual (for, while, or do-while).
Add a clear skip condition: if (skip_me) continue;.
In while / do-while, update the counter beforecontinue.
Put the “real work” after the skip test so unwanted items never reach it.
Piece
Required?
Role
Enclosing loop
Yes
continue is illegal outside loops
Skip condition
Usually
When to jump to the next iteration
Counter update (while)
Yes if needed
Avoid infinite loops before continue
Pseudocode
Pseudocode
for each item in list:
if item should be ignored:
continue // skip to next item
process item // only “good” items reach here
// loop finishes after all items
// while form — update first:
i = 0
while i < n:
i = i + 1
if i is even:
continue
print i
Reference
Cheat Sheet
Keep these facts handy while writing loop filters.
Topic
Detail
Syntax
continue;
Valid in
for, while, do-while only
Effect
Skip rest of this iteration; loop continues
vs break
continue skips one pass; break leaves the loop
for + continue
Increment (i++) still runs
while + continue
Update the counter before continue
Compile
gcc file.c -std=c11 -o out
Try it
Live Preview
Simulate how continue skips iterations. Same idea as the C examples below.
Browser simulation of continue control flow (same idea as the C examples below).
Result
i = 0 → print
i = 1 → print
i = 2 → continue (skip print)
i = 3 → print
i = 4 → print
output: 0 1 3 4
Trace
Worked Walkthrough — Print Odds Only
Loop from 1 to 10 and print only odd numbers by skipping evens with continue.
Trace
for i = 1 … 10:
if i is even → continue // skip printf
else → print i
1 → odd → print
2 → even → skip
3 → odd → print
…
10 → even → skip
Result: 1 3 5 7 9
Loop still visited every i — it just skipped the print
Code
C Examples
Compile every example with gcc file.c -std=c11 -o out. Short programs you can copy and run.
Example 1 — continue in a for Loop
Print 0–4 except 2. In a for loop, i++ still runs after continue.
C
#include <stdio.h>
int main(void) {
for (int i = 0; i < 5; i++) {
if (i == 2) {
continue;
}
printf("%d\n", i);
}
return 0;
}
Output
0
1
3
4
How It Works
Loop starts.i goes from 0 to 4.
Normal passes. For 0 and 1, the if is false, so each value prints.
Skip one. When i == 2, continue jumps past printf.
Increment still runs. The for does i++, then continues with 3 and 4.
Example 2 — Print Only Odd Numbers
Filter with continue: skip even values, print the odds.
C
#include <stdio.h>
int main(void) {
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
continue;
}
printf("%d ", i);
}
printf("\n");
return 0;
}
Output
1 3 5 7 9
How It Works
Visit every number. The loop still runs for 1 through 10.
Test even.i % 2 == 0 means “even.”
Skip print. Evens hit continue and never reach printf.
Print odds. Odds fall through to printf → 1 3 5 7 9.
Example 3 — Sum Positive Values Only
Skip zeros and negatives when summing an array—a practical filter pattern.
C
#include <stdio.h>
int main(void) {
int data[] = {10, -3, 5, 0, 8, -1};
int n = 6;
int sum = 0;
for (int i = 0; i < n; i++) {
if (data[i] <= 0) {
continue;
}
sum += data[i];
}
printf("Sum of positives: %d\n", sum);
return 0;
}
Output
Sum of positives: 23
How It Works
Scan the array. Visit each element once.
Reject non-positives.-3, 0, and -1 trigger continue.
Add the rest. Only 10, 5, and 8 update sum.
Result.10 + 5 + 8 = 23—no deep nesting around the add.
Edge Cases & Pitfalls
Check these before relying on continue in real projects.
while
Infinite loop risk
In while / do-while, if you continue before updating the counter, the same condition repeats forever. Increment first, or prefer for.
switch
Not for switch
continue is only for loops. Inside switch, use break to leave a case.
compare
Not the same as break
continue skips one pass; break ends the loop. Mixing them up changes program logic completely.
scope
Outside a loop
continue at file or function scope (not inside a loop) is a compile error.
Analysis
Performance Notes
Approach
Cost
Best for
continue filter
Still visits every item
Skip work on bad items; clearer than deep nesting
break on find
Stops early
Search when one match is enough
Nested if around body
Same work, harder to read
Avoid when a top-level continue is clearer
continue itself is free. It does not reduce how many times the loop runs—it only skips the rest of that pass. Use break when you can stop early.
Remember
Key Takeaways
Role: skip the rest of this iteration; loop keeps going.
for:i++ still runs after continue.
while: update the counter before continue.
Pattern: filter unwanted values without deep nesting.
One line:continue skips this pass and keeps the loop alive—use it to filter, not to stop.
Frequently Asked Questions
continue skips the rest of the current loop iteration and jumps to the next one. The loop itself keeps running—unlike break, which exits the loop entirely.
break leaves the loop completely. continue only skips to the next iteration. Use break to stop searching; use continue to skip unwanted values while the loop runs on.
No. In C, continue is only valid inside loops (for, while, do-while). switch uses break to exit a case, not continue.
Yes, in while and do-while loops if you continue before incrementing the counter. In a for loop, continue still runs the increment step (i++), so it is usually safer there.
Yes. continue skips the rest of the body and jumps to the do-while condition check. Remember to update loop variables before continue when needed.
No. continue jumps to the for loop's increment expression, then re-checks the condition. That is why continue in for is less likely to cause infinite loops than in while.