Recall & Review
beginner
What does the
continue statement do in a loop?It skips the current iteration and immediately jumps to the next iteration of the loop.
Click to reveal answer
beginner
In which types of loops can you use the
continue statement in Java?You can use
continue in for, while, and do-while loops.Click to reveal answer
intermediate
What happens if
continue is used inside a nested loop?It only affects the innermost loop where it is used, skipping to the next iteration of that loop.
Click to reveal answer
beginner
Example: What will be printed by this code?<br>
for (int i = 1; i <= 5; i++) {<br> if (i == 3) continue;<br> System.out.print(i + " ");<br>}The output will be:
1 2 4 5 <br>Because when i is 3, continue skips printing it.Click to reveal answer
intermediate
Why might you use
continue instead of if-else inside a loop?Using
continue can make code cleaner by skipping unwanted cases early, avoiding nested if-else blocks.Click to reveal answer
What does the
continue statement do inside a loop?✗ Incorrect
The
continue statement skips the rest of the current loop iteration and moves to the next one.In a
for loop, what happens after continue is executed?✗ Incorrect
After
continue, the loop updates the variable and starts the next iteration.Can
continue be used in a while loop?✗ Incorrect
continue works in all loop types including while.What will this code print?<br>
for (int i = 0; i < 4; i++) {<br> if (i == 2) continue;<br> System.out.print(i);<br>}✗ Incorrect
When
i is 2, continue skips printing it, so output is 0,1,3.If
continue is inside nested loops, which loop does it affect?✗ Incorrect
continue affects only the loop it is directly inside.Explain how the
continue statement changes the flow inside a loop.Think about what happens when you want to skip some steps but keep looping.
You got /3 concepts.
Describe a situation where using
continue makes your code simpler than using nested if-else.Imagine checking many conditions but only want to act on some.
You got /3 concepts.