Recall & Review
beginner
What is a counter-based while loop?
A counter-based while loop is a loop that repeats a set of instructions while a counter variable meets a condition. The counter changes each time the loop runs, usually increasing or decreasing by 1.
Click to reveal answer
beginner
How do you initialize a counter for a while loop in Python?
You create a variable before the loop starts and set it to a starting number, often 0 or 1. For example:
counter = 0
Click to reveal answer
beginner
Why must you update the counter inside the while loop?
If you don't change the counter inside the loop, the condition may never become false, causing an infinite loop that never stops.
Click to reveal answer
beginner
Write a simple counter-based while loop that prints numbers 1 to 5.
counter = 1
while counter <= 5:
print(counter)
counter += 1Click to reveal answer
beginner
What happens if the counter condition is false at the start of the while loop?
The loop body will not run even once because the condition is checked before the loop starts.
Click to reveal answer
What is the first step when creating a counter-based while loop?
✗ Incorrect
You must first create and set the counter variable before the loop starts.
What happens if you forget to update the counter inside the while loop?
✗ Incorrect
Without updating, the condition never changes, so the loop never ends.
Which of these is a correct condition for a counter starting at 0 to run 5 times?
✗ Incorrect
Using 'counter < 5' runs the loop while counter is 0,1,2,3,4 which is 5 times.
Where do you put the counter update in a while loop?
✗ Incorrect
The counter must be updated inside the loop to change the condition each time.
What will this code print?
counter = 3
while counter > 0:
print(counter)
counter -= 1✗ Incorrect
The loop prints 3, then 2, then 1, then stops when counter is 0.
Explain how a counter-based while loop works and why updating the counter is important.
Think about how the loop knows when to stop.
You got /4 concepts.
Write a simple Python while loop that counts down from 5 to 1 and prints each number.
Start with counter = 5 and reduce it by 1 each time.
You got /4 concepts.