Recall & Review
beginner
What is a while loop in Python?
A while loop repeatedly runs a block of code as long as a given condition is true.
Click to reveal answer
beginner
Why do we need a while loop instead of just running code once?
Because sometimes we want to repeat actions until something changes, like waiting for user input or a condition to become false.
Click to reveal answer
beginner
Give a real-life example where a while loop is useful.
Imagine filling a glass with water until it is full. You keep pouring water (loop) until the glass is full (condition becomes false).
Click to reveal answer
intermediate
What happens if the condition in a while loop never becomes false?
The loop will run forever, causing an infinite loop, which can freeze or crash the program.
Click to reveal answer
intermediate
How does a while loop differ from a for loop?
A while loop repeats based on a condition and can run an unknown number of times, while a for loop runs a set number of times over a sequence.
Click to reveal answer
What does a while loop do in Python?
✗ Incorrect
A while loop keeps running the code block as long as the condition remains true.
When should you use a while loop instead of a for loop?
✗ Incorrect
Use a while loop when the number of repetitions depends on a condition, not a fixed count.
What is a risk of using a while loop without changing the condition inside it?
✗ Incorrect
If the condition never becomes false, the loop runs endlessly, causing an infinite loop.
Which of these is a good example of a while loop use?
✗ Incorrect
Waiting for user input until it meets a condition is a classic use of a while loop.
What must you always do inside a while loop to avoid infinite loops?
✗ Incorrect
You must update something inside the loop so the condition eventually becomes false.
Explain why a while loop is useful and give a simple example.
Think about doing something again and again until a rule changes.
You got /2 concepts.
Describe what can happen if a while loop's condition never becomes false and how to prevent it.
Consider what happens if you never stop repeating.
You got /3 concepts.