Junior Codes
Willow Island

Python for Loops for Kids

Repeat an instruction without typing it again and again.

Try this mission free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

for loops, explained simply

Imagine planting ten flowers by writing the same line ten times. It works, but it is slow and easy to get wrong. A loop lets you write the instruction once and tell Python how many times to repeat it.

A for loop starts with for, then a variable name, then in, then something to go through, and ends with a colon. The lines that should repeat are indented underneath, usually by four spaces.

Each time round the loop, the variable holds the next value. With range(5) that means 0, 1, 2, 3 and 4, which is five repeats in total.

Example: Plant a row of flowers

for flower in range(4):
    print("Plant a flower")
print("The garden is ready!")

Output

Plant a flower
Plant a flower
Plant a flower
Plant a flower
The garden is ready!

The last line is not indented, so it runs once, after the loop has finished.

Try this

  • Change 4 to 10 and watch the garden grow.
  • Print the loop variable itself inside the loop to see the numbers it counts through.
  • Indent the last line too and notice how the output changes.

Practise it in Wonderwild

“A garden on repeat”

Mission 3 in Willow Island, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Try this mission free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

Questions parents and kids ask

Why does range(5) start at 0?+

Python, like most programming languages, starts counting from 0. range(5) still repeats five times: 0, 1, 2, 3, 4.

What does the indentation do in a loop?+

Indentation tells Python which lines belong inside the loop. Indented lines repeat; lines that are not indented run after the loop ends.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course