CurriculumThe Dragon Repeats

Python for Loops and range() for Kids

A for loop runs the same instruction several times, so a child writes one line instead of twenty.

15 exercises5 lessonsAges 10+PRO
See what PRO unlocks →

What this topic covers

The appeal of a loop is immediate — one instruction, repeated — and children take to it quickly. The difficulty is not the loop, it is range(). range(5) produces five numbers starting at 0 and never reaches 5, which is surprising to everyone the first time and is the source of nearly every off-by-one error a beginner writes.

This topic gives range() a segment of its own rather than mentioning it in passing. Children predict what a range will produce before running it, and see the difference between how many times a loop runs and what the numbers inside it actually are.

The last idea is accumulation: carrying a value forward from one pass to the next to build up a total. It combines loops with the variable-updating from the previous topic, and it is the first genuinely powerful thing a child can write here.

Python from this topic

for i in range(3):
    print("Roar", i)

Output

Roar 0
Roar 1
Roar 2

Python covered here

  • The for loop
  • range(n) — counting from zero
  • Why range(n) never reaches n
  • Using the loop variable inside the loop
  • Building a running total across passes
  • Loops and if statements together

The mistake this topic is built to fix

Common mistakeA child expects range(5) to count 1, 2, 3, 4, 5.

It produces 0, 1, 2, 3, 4 — five numbers, but not the five expected. Off-by-one errors from this are so common that the topic devotes a whole segment to predicting range output before writing any loop that depends on it.

The lessons, in order

  1. Doing something many timesfor and range() — one instruction, run again and again.3 exercises
  2. What range() actually countsrange(n) gives n numbers starting at 0 — and never reaches n itself.3 exercises
  3. Building up a totalCarrying a value forward, loop pass after loop pass.3 exercises
  4. The Dragon PatrolLoops, counting, and decisions — all working together, pass after pass.3 exercises
  5. Loops inside loopsA loop inside a loop, for checking every cell of a grid — and the order that surprises everyone.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 →