Recall & Review
beginner
What does the
continue statement do in a loop?It skips the rest of the current loop iteration and immediately starts the next iteration of the loop.
Click to reveal answer
beginner
In which types of loops can you use the
continue statement in C++?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
True or False: The
continue statement exits the entire loop.False.
continue skips to the next iteration but does not exit the loop. The break statement exits the loop.Click to reveal answer
beginner
Example: What will be the output of this code?<br>
for (int i = 1; i <= 5; i++) {
if (i == 3) continue;
std::cout << i << " ";
}The output will be:
1 2 4 5 <br>The number 3 is skipped because when i == 3, continue skips printing it.Click to reveal answer
What does the
continue statement do inside a loop?✗ Incorrect
The
continue statement skips the remaining code in the current loop iteration and moves to the next iteration.In a
for loop, what happens after a continue statement is executed?✗ Incorrect
After
continue, the loop updates the loop variable (like incrementing) and starts the next iteration.Can
continue be used in a while loop?✗ Incorrect
continue works in all loop types including while loops.What is the difference between
continue and break?✗ Incorrect
continue skips the rest of the current iteration, while break stops the loop completely.If
continue is used 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 real-life example where using
continue in a loop would be helpful.Imagine sorting mail and skipping junk mail without stopping the whole process.
You got /3 concepts.