The dragon explains
while — repeat until something changes
The dragon: for loops repeat a NUMBER of times, decided in advance. while loops are different — they repeat UNTIL something changes.
The dragon: while CONDITION: keeps going as long as the condition is True. No fixed count anywhere.
example.pyPython 3patience = 3while patience > 0: print("Pacing...") patience = patience - 1
OutputPacing... Pacing... Pacing...The dragon: Every pass checks the condition FRESH. The moment patience hits 0, the loop stops — nobody tells it '3 times', it just keeps going until False.
example.pyPython 3patience = 3while patience > 0: print("Pacing...") patience = patience - 1
The dragon: Here's the trap: if nothing inside the loop ever changes patience, the condition is ALWAYS True. The loop never stops.
example.pyPython 3patience = 3while patience > 0: print("Pacing...")
The dragon: If that happens for real, you'll see a message about your code getting stuck in a loop, and it reboots automatically. That's not a crash — it's the game catching exactly this.
The dragon: The condition can be a question about the world, too. while front_is_clear(): keeps me walking until something blocks the way — however long the tunnel is.
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 1
patience = 3, and the loop body never changes patience. What happens?
question.pyPython 3patience = 3while patience > 0: print("Pacing...")
- It repeats forever — patience > 0 never becomes FalseCorrect
- It runs exactly 3 times, then stops on its own
- It causes an error immediately, before running at all
Why: Nothing inside the loop ever changes patience, so patience > 0 stays True forever, and the loop never ends. This is the single most common while-loop mistake — always ask yourself: what, inside this loop, actually changes the condition?
In the game
What you'll practice
Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.
- 1
GuidedYour first try
The dragon paces back and forth while its patience is above 0. Patience starts at 3 and drops by 1 each pace. Print 'Pacing...' each time it paces.
- +2
PracticeTwo more, on your own
This lesson is part of PRO.
PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.
Unlock this lesson with PROStuck three times? The game offers the answer — unasked.