Challenge - 5 Problems
Continue Statement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of loop with continue skipping even numbers
What is the output of this Java code snippet?
Java
for (int i = 1; i <= 5; i++) { if (i % 2 == 0) { continue; } System.out.print(i + " "); }
Attempts:
2 left
💡 Hint
The continue statement skips the current iteration when the number is even.
✗ Incorrect
The loop prints numbers from 1 to 5. When the number is even, continue skips printing it. So only odd numbers 1, 3, and 5 are printed.
❓ Predict Output
intermediate2:00remaining
Effect of continue in nested loops
What will be printed by this Java code?
Java
for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (j == 2) { continue; } System.out.print(i + "-" + j + " "); } }
Attempts:
2 left
💡 Hint
The continue skips printing when j equals 2, but the outer loop continues.
✗ Incorrect
For each i, the inner loop prints j except when j is 2. So j=1 and j=3 print for each i.
❓ Predict Output
advanced2:00remaining
Continue statement effect on while loop
What is the output of this Java code?
Java
int i = 0; while (i < 5) { i++; if (i == 3) { continue; } System.out.print(i + " "); }
Attempts:
2 left
💡 Hint
The continue skips printing when i equals 3, but i is incremented before the check.
✗ Incorrect
i increments from 0 to 5. When i is 3, continue skips printing. So output excludes 3.
❓ Predict Output
advanced2:00remaining
Continue inside for loop with multiple conditions
What will this Java code print?
Java
for (int i = 1; i <= 6; i++) { if (i % 2 == 0 || i % 3 == 0) { continue; } System.out.print(i + " "); }
Attempts:
2 left
💡 Hint
Numbers divisible by 2 or 3 are skipped.
✗ Incorrect
Numbers 2,3,4,6 are skipped because 2 and 4 are divisible by 2, 3 and 6 by 3. Only 1 and 5 print.
❓ Predict Output
expert3:00remaining
Behavior of continue in labeled loops
Consider this Java code with labeled loops. What is the output?
Java
outer: for (int i = 1; i <= 3; i++) { inner: for (int j = 1; j <= 3; j++) { if (i == j) { continue outer; } System.out.print(i + "-" + j + " "); } }
Attempts:
2 left
💡 Hint
The continue outer skips the rest of the inner loop and moves to the next iteration of the outer loop when i == j.
✗ Incorrect
When i equals j, continue outer skips the rest of the inner loop and moves to the next iteration of the outer loop. For i=1, j=1 triggers continue outer, skipping the entire inner loop, so nothing prints for i=1. For i=2, j=1 prints 2-1, then j=2 triggers continue outer. For i=3, j=1 and j=2 print before j=3 triggers continue outer.