🔁 Loops: do it again
Why: Repeat work millions of times with for and while.
Unlocks: Lists — and the pattern behind every game loop.
When you raced the computer, its superpower wasn't intelligence — it was repetition without boredom. Loops are how you hand your program that superpower. for i in range(5): means “run the indented lines 5 times, counting i as 0, 1, 2, 3, 4.”
Loops + variables = programs that accumulate. Watch a total grow:
There's a second loop, while: “keep repeating as long as this condition is true.” It's an if that refuses to move on:
And now, a rite of passage. What if the condition never becomes false? You get an infinite loop — the program runs forever. Every programmer writes one eventually, usually by accident. You'll write yours on purpose, because this site gives you a real ■ Stop button that can kill it. Try it — run this, watch it spin, then press Stop:
How many times does the body of for i in range(3): run, and what values does i take?
What makes a while loop infinite?
🔍 Go deeper: watch a loop spin one iteration at a time, variables updating live → PyDebug: Loops.