0
0
Javaprogramming~20 mins

Continue statement in Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Continue Statement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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 + " ");
}
A1 3 5
B2 4
C1 2 3 4 5
D1 3 4 5
Attempts:
2 left
💡 Hint
The continue statement skips the current iteration when the number is even.
Predict Output
intermediate
2: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 + " ");
    }
}
A1-1 1-3 2-1 2-3 3-1 3-3
B1-1 1-2 1-3 2-1 2-2 2-3 3-1 3-2 3-3
C1-2 2-2 3-2
D1-1 2-1 3-1
Attempts:
2 left
💡 Hint
The continue skips printing when j equals 2, but the outer loop continues.
Predict Output
advanced
2: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 + " ");
}
A2 3 4 5
B1 2 3 4 5
C1 2
D1 2 4 5
Attempts:
2 left
💡 Hint
The continue skips printing when i equals 3, but i is incremented before the check.
Predict Output
advanced
2: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 + " ");
}
A1 5 6
B1 5
C1 2 3 4 5 6
D1 4 5
Attempts:
2 left
💡 Hint
Numbers divisible by 2 or 3 are skipped.
Predict Output
expert
3: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 + " ");
    }
}
A1-2 2-3 3-1
B1-2 1-3 2-1 2-3 3-1 3-2
C2-1 3-1 3-2
D1-2 1-3 2-1 3-1 3-2
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.