Python for Loops and range() Explained for Kids

for and range() — one instruction, run again and again.

  • Lesson 1 of 5
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

Doing something many times

  1. The dragon: You've written the same print() three times before to make three lines. There's a much better way.

  2. The dragon: for i in range(3): repeats the indented lines below it — three times, automatically.

    example.pyPython 3
    for i in range(3):    print("Roar!")
    OutputRoar! Roar! Roar!
  3. The dragon: Change the number, change the count. No copy-pasting needed.

    example.pyPython 3
    for i in range(5):    print("Flap!")
    OutputFlap! Flap! Flap! Flap! Flap!
  4. The dragon: i is the loop's own counter — it changes every single time the loop runs.

    example.pyPython 3
    for i in range(4):    print(i)
    Output0 1 2 3
  5. The dragon: A loop isn't just 'repeat this text' — it's 'run this code, with a different i each time.'

  6. The dragon: Now a corridor full of gems. One lap of the loop: one step, one grab. Watch the same two lines light up again and again.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 1

    for i in range(3): print("Go!") — does i actually change anything here?

    question.pyPython 3
    for i in range(3):    print("Go!")
    • i changes each time, but this code never uses it, so the output looks the sameCorrect
    • No — i only exists if you print it
    • This is exactly the same as writing print("Go!") three separate times, with no real difference

    Why: i really does become 0, then 1, then 2 — but this code never uses i, so you can't tell from the output. The loop is still doing real work each pass, even when that work happens to look identical.

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. 1

    GuidedYour first try

    Three gems in a row. This loop walks the dragon three steps — but nothing picks the gems up. Add grab() INSIDE the loop (indented, under move_right()), so every lap is a step AND a grab.

  2. +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 PRO

Stuck three times? The game offers the answer — unasked.