Java Continue — Java Technical Interview Questions & Answers
Java Continue
Java Continue
- continue skips the rest of this round and goes to the next round. The loop does not end. Useful to ignore bad values: skip negatives, skip one id.
- In a for loop, after continue the update (i++) still happens. Then the condition is checked again. break exits; continue keeps looping.
- Same sample loop, continue at i == 3 vs break at i == 3 — outputs are different. Interviewers love that comparison. Don’t say continue “stops the loop”.
- Let's take this on the board with one tiny Main class — no extra files. Java Continue — output: 1, 2, 4, 5. When i is 3, continue skips that print and goes to i++. Start from main, go line by line, and stop at each print. That output is the proof for Continue.
Technical Interview Tip: Same loop: continue at i == 3 vs break. Compare output.
Code Examples for Java Continue
Example
// Java Continue
public class Main {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue;
}
System.out.println(i);
}
}
}Java Continue — output: 1, 2, 4, 5. When i is 3, continue skips that print and goes to i++.
How to Explain Java Continue to an Interviewer
Does continue stop the loop?
No Only this round is skipped
When do you use continue?
Ignore bad values Skip one case
After continue in for, does i++ still run?
Yes