Font size
Worksheets2.2.2 - 2.2.3 Iteration Extra Practice
Total questions: 28
Worksheet time: 22mins
What is the main condition for a `while` loop to keep running?
As long as a list is not empty
As long as the condition is True
Until the function ends
As long as a variable is undefined
What kind of loop runs indefinitely if the condition never becomes false?
Controlled loop
Break loop
Infinite loop
Timed loop
What will this code print? counter = 0 while counter < 3: print(counter) counter += 1
0 1 2
1 2 3
0 1 2 3
1 2
Which operator is typically used to check a condition in a `while` loop?
+
==
=
%
What does a `for` loop iterate over?
Only strings
Only numbers
A sequence
A condition
Which keyword is used to start a `for` loop in Python?
iterate
loop
for
range
What is the correct structure for a `for` loop?
for i = range(5)
for i in range(5):
loop i in range(5):
for (i in range 5)
Which situation is best for a `for` loop?
Only strings
Only numbers
Iterating over a sequence
A condition
What does the `break` statement do?
Pauses the loop
Skips one loop cycle
Ends the loop immediately
Repeats the loop
When is `break` commonly used?
When a value reaches a limit
To reset a loop
To increase a variable
In variable declarations
True or False: `break` works in both `for` and `while` loops.
True
False
How does `break` affect loop flow?
Skips the current iteration
Skips the next iteration
Exits the loop
Starts the loop over
What does `continue` do in a loop?
Skips all remaining code in the loop for this iteration
Exits the loop
Starts the program over
Jumps to the end of the program
When should you use `continue`?
To stop a loop completely
To handle an error
To skip over part of the loop
To create a variable
True or False: The loop stops when it hits a `continue` statement.
False
True
Where is `continue` typically used?
At the top of the loop
After the loop ends
Inside a condition in the loop
Outside of all code blocks
What does the `pass` statement do?
Ends a loop
Acts as a placeholder
Skips the loop
Restarts the code
Which situation is best for using `pass`?
When code isn't written yet
When checking conditions
When skipping errors
When comparing values
What will this loop do? while True: pass
Run once
Print something
Run forever
Throw an error
What is a nested loop?
A loop with no end
A loop inside another loop
A loop that runs twice
A loop with multiple conditions
True or False: Nested loops can contain both `for` and `while`.
True
False
How many times will this print run? for i in range(2): for j in range(3): print("Repeat")
2
3
5
6
What is a compound condition?
A condition that loops
A condition using `and` or `or`
A loop that breaks
A placeholder
Which is a compound conditional loop? while health > 0 and shield > 0:
A loop with a single condition
A loop with multiple conditions using `and`
A loop that never ends
A loop with no conditions
Why use compound conditions in loops?
To reduce code complexity
To create errors
To replace `break`
To avoid using `for` or `while`
A coach wants to track each lap during a 10-lap race. The loop should start at lap 1 and end at lap 10.
Fill in the blank code to complete the loop:
for lap in range(1, ____ ): print("Lap", lap, "complete")
A bakery tracks every batch of cookies it makes in a day. If they make 15 batches, starting with batch 1, how should the loop be written?
for batch in range(1,____): print("Batch", batch, "is cooling")
A marathon runner logs each kilometer in a 42-kilometer race. The log starts at kilometer 1 and goes to 42.
for km in range(1,____ ): print("You’ve reached kilometer", km)
