0
0
Javaprogramming~5 mins

Continue statement in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARestarts the entire program
BExits the loop completely
CPauses the loop until a condition is met
DSkips the rest of the current iteration and moves to the next iteration
In a for loop, what happens after continue is executed?
AThe loop variable is updated and the next iteration starts
BThe loop stops immediately
CThe program crashes
DThe loop variable resets to zero
Can continue be used in a while loop?
AOnly in <code>do-while</code> loops
BNo, it only works in <code>for</code> loops
CYes, it skips to the next iteration
DOnly inside <code>switch</code> statements
What will this code print?<br>
for (int i = 0; i < 4; i++) {<br>  if (i == 2) continue;<br>  System.out.print(i);<br>}
A0123
B013
C123
D023
If continue is inside nested loops, which loop does it affect?
AOnly the innermost loop where it appears
BAll loops at once
COnly the outermost loop
DIt exits all loops
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.