Python For Loops for Kids: 12 Examples That Actually Make Sense

Michael Murr··9 min read

A Python for loop runs the same instructions over and over, with a small change each time. It is one of the first things kids learn in Python because it is genuinely useful from the first lesson and shows up in almost every program they will ever write. This guide walks through 12 Python for loop examples that build on each other, with the actual code, what it does, and the small thinking shift that makes loops click.

Key Takeaways

  • A for loop in Python lets you repeat instructions a controlled number of times, or step through a list of items one by one.
  • The most common form is for i in range(n): which counts from 0 to n-1, but you can also loop over lists, strings, or any other sequence.
  • The 12 examples below are ordered from simplest to most complex, each introducing one new idea while reusing what came before.
  • Children are typically ready for Python for loops between ages 10 and 13, ideally after a foundation in Scratch where the same concept appears as the repeat block.
  • A for loop with a confusing variable name (like i) is harder to learn than one with a meaningful name (like count or letter). The choice matters more than most beginners realise.

Table of Contents

What a Python For Loop Actually Does

Before the examples, the core idea: a for loop tells Python "do this thing once for each item in this collection." The collection might be a range of numbers, a list of names, or the letters in a word. Each time through the loop, Python sets a variable to the current item and runs the indented code below.

The minimum form looks like this:

for i in range(3):
    print("Hello!")

This runs the print line three times, producing:

Hello!
Hello!
Hello!

The variable i takes the value 0, then 1, then 2, but the code inside the loop ignores it. The loop just runs three times because range(3) produces three values.

That is the whole concept. Everything else is variations on this idea.

Example 1: Print Something Five Times

The simplest possible for loop:

for i in range(5):
    print("Hello, world!")

Output:

Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!

What's new: The range(5) produces the numbers 0, 1, 2, 3, 4, which gives five iterations. The variable i is unused here, which is fine for beginners learning the structure.

Example 2: Count From 1 to 10

Most beginners try this and immediately hit a confusion: range(10) actually counts from 0, not 1.

for number in range(1, 11):
    print(number)

Output:

1
2
3
4
5
6
7
8
9
10

What's new: range(1, 11) starts at 1 and stops before 11. The "stop before" rule trips up almost every beginner once. The variable name number makes the code more readable than i.

Example 3: Sum the Numbers From 1 to 100

The first loop that does something genuinely useful: adding up numbers.

total = 0
for number in range(1, 101):
    total = total + number
print(total)

Output:

5050

What's new: A variable defined outside the loop (total = 0) gets updated inside the loop. Each iteration adds the current number to the running total. This is the most important loop pattern in early Python: accumulate something across iterations.

Example 4: Print a Times Table

A practical loop a child can actually use for school work:

times_table = 7
for number in range(1, 11):
    print(times_table, "x", number, "=", times_table * number)

Output:

7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

What's new: Combining the loop variable with another value to produce a calculation. The child can change times_table = 7 to any number and immediately have a complete times table for it.

Example 5: Loop Through a List of Names

For loops are not just for numbers. They work with any list:

names = ["Alex", "Sam", "Maya", "Jordan"]
for name in names:
    print("Hello,", name)

Output:

Hello, Alex
Hello, Sam
Hello, Maya
Hello, Jordan

What's new: Looping directly over a list. The variable name takes each value in turn. This is one of the most common patterns in real Python: do something with each item in a collection.

Example 6: Count Letters in a Word

A string in Python is essentially a list of letters, which means you can loop through it:

word = "elephant"
count = 0
for letter in word:
    count = count + 1
print(count)

Output:

8

What's new: Looping over a string letter by letter, combined with the accumulator pattern from Example 3. (Of course, len(word) would do the same thing, but writing it as a loop teaches the underlying mechanics.)

Example 7: Find the Largest Number in a List

A loop that compares values as it goes:

numbers = [42, 17, 89, 23, 51]
biggest = numbers[0]
for number in numbers:
    if number > biggest:
        biggest = number
print(biggest)

Output:

89

What's new: Combining a for loop with an if statement. The pattern starts with a guess (the first number) and updates it whenever a larger one appears. This is a classic algorithm pattern that shows up everywhere in real programming.

Example 8: Loop Backwards

Sometimes you want to count down instead of up:

for number in range(10, 0, -1):
    print(number)
print("Blast off!")

Output:

10
9
8
7
6
5
4
3
2
1
Blast off!

What's new: The third argument to range is the step. range(10, 0, -1) goes from 10, stops before 0, stepping by -1 each time. This is the same as the standard pattern, just with a different direction.

Example 9: Skip Numbers (Step)

The step argument is not just for going backwards. It can skip values:

for even in range(2, 21, 2):
    print(even)

Output:

2
4
6
8
10
12
14
16
18
20

What's new: A step of 2 means "go up by 2 each time." A step of 5 would give you multiples of 5. This pattern is useful when you only want certain values, not every single number.

Example 10: Print a Triangle of Stars

A loop that produces visual output:

for row in range(1, 6):
    print("*" * row)

Output:

*
**
***
****
*****

What's new: The * operator on a string repeats the string. So "*" * 3 gives "***". Combining this with a loop that increases the count produces a visible shape. This is one of the first projects where children see code producing real visual output.

Example 11: Multiplication Grid (Nested Loops)

A loop inside a loop. This is where loops get genuinely powerful:

for row in range(1, 6):
    for col in range(1, 6):
        product = row * col
        print(product, end="\t")
    print()

Output:

1   2   3   4   5
2   4   6   8   10
3   6   9   12  15
4   8   12  16  20
5   10  15  20  25

What's new: A nested loop runs the inner loop completely for each iteration of the outer loop. Here, for each row, we print 5 columns, then move to a new line with print(). The \t is a tab character that lines up the numbers neatly. Nested loops produce 2D shapes, grids, and tables.

Example 12: Loop Through a Dictionary

Python dictionaries store key-value pairs. You can loop through them in several ways:

ages = {"Alex": 9, "Sam": 11, "Maya": 13}
for name, age in ages.items():
    print(name, "is", age, "years old.")

Output:

Alex is 9 years old.
Sam is 11 years old.
Maya is 13 years old.

What's new: The .items() method gives you both the key and the value in each iteration. This is one of the most common patterns when working with structured data, and a great preparation for working with real datasets later.

How to Practise These Loops

Each of these examples is short enough to type into a Python interpreter or a file in 30 seconds. The most useful exercise is not just copying them but modifying them. Try these tweaks:

  • Change Example 1 to print something different
  • Change Example 2 to count from 5 to 25
  • Change Example 4 to print the 12 times table instead
  • Add another name to Example 5
  • Change Example 7 to find the smallest number instead of the largest
  • Modify Example 10 to print a 10-row triangle

Each modification tests a slightly different understanding. Children who can complete all six modifications without looking at the original code have genuinely understood the pattern.

A parent named Tahir Canberk summarised what good Python instruction looks like for a child working through patterns like these: "Michael is a great teacher that takes you from 0 to the top. He explains clearly and creates great challenges that help tremendously. He is also helpful and responsive." The "great challenges" piece is exactly what these modifications produce. Practice with variations beats passive reading every time.

For broader context on Python for kids, see our Python for kids complete guide and our online Python tutor for kids guide.

FAQ

What is a for loop in Python for kids?

A for loop is a way to make Python do the same thing several times. You write the instruction once, and Python repeats it for each item in a list or each number in a range. For kids, the simplest example is for i in range(5): print("Hello!"), which prints "Hello!" five times. The same concept appears in Scratch as the repeat block.

What age can kids learn Python for loops?

Most children are ready to learn Python for loops between ages 10 and 13, ideally after a foundation in Scratch or a similar visual tool. Children who already understand the idea of repetition from Scratch's repeat block typically understand Python for loops within one or two sessions. Without that foundation, the concept usually takes longer to click.

What's the difference between for loops and while loops in Python?

A for loop runs a known number of times (loop through these 5 names, repeat this 10 times). A while loop runs as long as a condition is true (keep asking until the user types "stop"). Both are useful in different situations. For loops are typically introduced first because they are easier to predict and harder to accidentally make infinite.

How do I make a Python for loop count from 1 instead of 0?

Use range(1, n+1) where n is the largest number you want. So to count from 1 to 10, write range(1, 11). The "stop before" rule means range(1, 11) produces 1, 2, 3, ..., 10 (stopping before 11). This trips up almost every beginner once and then becomes second nature.

Can a for loop go through letters in a word?

Yes. A string in Python behaves like a list of letters, so you can write for letter in "hello": print(letter) to print each letter on its own line. This works for any string and is one of the most useful features of for loops in Python.

Why does my Python for loop only run once?

The most common cause is incorrect indentation. Everything that should run inside the loop must be indented (typically 4 spaces) below the for line. If only one line is indented and the rest are not, only that one line runs in the loop. Check the indentation carefully if your loop is misbehaving.


Want a tutor's help getting your child confident with Python for loops and beyond? Book a free Discovery Call, 20 minutes, no obligation, and you'll leave knowing exactly where your child should start.

Enjoyed this article?

Your child can learn this and more with a dedicated 1-on-1 tutor.

Book a Free Discovery Call