CurriculumThe Dragon's Vigil
Python while Loops, break and continue for Kids
A while loop repeats for as long as something stays true, which makes it the right tool when you do not know in advance how many times to go round.
What this topic covers
A for loop runs a known number of times. A while loop runs until a condition stops holding — which is more flexible and considerably easier to get wrong. The classic failure is forgetting to change the thing being tested, so the condition never becomes False and the loop runs forever.
Rather than warning about infinite loops in the abstract, this topic puts children in front of them safely. All code runs in a sandbox with an execution limit, so a runaway loop stops on its own and becomes something to diagnose rather than something to fear.
break and continue follow, and the distinction between them is drawn sharply: break abandons the whole loop, continue abandons only the current pass. Children who blur the two write code that looks nearly right and behaves nothing like it should.
Python from this topic
gold = 0
while gold < 3:
gold = gold + 1
print(gold)Output
1
2
3Python covered here
- The while loop
- Conditions that change over time
- Why a loop can run forever, and how to spot it
- break — leaving a loop immediately
- continue — skipping one pass only
- Choosing between for and while
The mistake this topic is built to fix
Common mistakeA child uses continue expecting the loop to stop, or break expecting it to skip one item.
The two are easy to blur because both interrupt the normal flow. The topic contrasts them on the same task so the difference in result is obvious rather than described.
The lessons, in order
- while — repeat until something changesA loop that runs until a condition stops being True — and the trap of forgetting to update it.3 exercises
- break — leaving earlyStopping a loop the instant something happens, before its condition would end it naturally.3 exercises
- continue — skipping just onebreak stops everything. continue skips just this one pass and keeps going.3 exercises
- The Full Night Patrolwhile, break, and continue — all three, working together.3 exercises
- Boundaries and every-path updatesOff-by-one at the edge of a while loop — and the update that has to happen on EVERY branch, not just one.3 exercises
Lessons unlock in order within a topic, so nothing arrives before the idea it depends on. This topic is part of PRO — $6.99 unlocks it along with everything else.
Try it now
The very first level needs no account at all — see whether it clicks before signing up for anything.
Play the first level free →