Continue Statement
1. What It Does (beginner)
continue = skip this round only, jump to next iteration. Unlike break (exits fully), continue says "skip me, do next". Perfect for "print odds, skip evens".
2. Code — Odds Only + Labelled
for (int i = 1; i <= 5; i++) {
if (i % 2 == 0) continue; // skip evens (2,4)
System.out.print(i + " "); // 1 3 5
}
// labelled: skip outer round!
outer:
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (j == 2) continue outer; // skip rest of inner, next i!
System.out.print(i + "," + j + " ");
}
}
// prints 1,1 2,1 3,1 (j=2,3 skipped each time!)
3. Break vs Continue (exam table)
break |
continue |
|
|---|---|---|
| Effect | exits loop fully | skips to next iteration |
| Example output (skip 3?) | 0 1 2 (ends) | 0 1 2 4 5 (3 missing, rest continue) |
4. Traps
continueinwhilejumps to condition check (update first or infinite loop!). Infor, jumps to update (i++) — safer.- Labelled
continue outer= next round of outer (rare, exam loves trace!).
5. Exam Points
- Odd/even program + output trace — 3-5 marks, frequent.
- Break vs continue table + labelled trace — 5 marks, frequent.