Recall & Review
beginner
What does the
continue statement do inside a loop?It skips the rest of the current loop cycle 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?You can use
continue in both for loops and 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
Consider this code snippet:<br>
for i in range(5):
if i == 2:
continue
print(i)<br>What will be the output?The output will be:<br>0<br>1<br>3<br>4<br>The number 2 is skipped because
continue skips printing when i == 2.Click to reveal answer
intermediate
Why might you use
continue instead of if-else inside a loop?Using
continue can make the code cleaner by avoiding nested if-else blocks and clearly skipping unwanted cases.Click to reveal answer
What does the
continue statement do in a loop?✗ Incorrect
The
continue statement skips the rest of the current loop cycle and moves to the next iteration.In which loop types can
continue be used?✗ Incorrect
continue works in both for and while loops.What happens if
continue is used inside nested loops?✗ Incorrect
continue affects only the innermost loop where it is used.Given this code:<br>
for i in range(3):
if i == 1:
continue
print(i)<br>What is printed?✗ Incorrect
When
i == 1, continue skips printing, so only 0 and 2 are printed.Why might
continue improve code clarity?✗ Incorrect
continue helps avoid deep nesting by skipping to the next loop iteration early.Explain how the
continue statement changes the flow inside a loop.Think about what happens when the loop sees <code>continue</code>.
You got /3 concepts.
Describe a situation where using
continue makes your loop code easier to read.Consider how skipping some steps early can reduce indentation.
You got /3 concepts.