Lesson 6 of 30

Lesson 06 — Loops for counting and games

Title: Repeat actions without copying code

Description: Use loops to count, repeat messages, build patterns, and keep a tiny game running.

Why it matters for kids: Loops help computers do boring repeated work very fast.


1. Count with for

pythonpython
for number in range(1, 6):
    print(number)

range(1, 6) means start at 1 and stop before 6.


2. Cheer loop

pythonpython
for cheer in range(3):
    print("You can code!")

This prints the message three times.


3. Draw with text

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

Output:

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

4. Loop through a word

pythonpython
word = "Python"

for letter in word:
    print(letter)

Python can visit each letter one by one.


5. A simple while loop

pythonpython
energy = 3

while energy > 0:
    print("The robot walks.")
    energy = energy - 1

print("The robot needs charging.")

Use while when you want to continue until something changes.


6. Easy examples

pythonpython
for step in range(1, 4):
    print(f"Step {step}: jump!")
pythonpython
for coin in range(5):
    print("Collected a coin.")
pythonpython
countdown = 5

while countdown > 0:
    print(countdown)
    countdown = countdown - 1

print("Blast off!")

7. Mini challenge

Click each example to open it.

Example 1

Print numbers from 1 to 5.

Example 2

Print Hello three times.

Example 3

Print five stars on one line.

Example 4

Print a triangle made of stars.

Example 5

Loop through the word cat.

Example 6

Count down from 3 to 1.

Example 7

Print Hop! four times.

Example 8

Add 1 point inside a loop.

Example 9

Use a while loop with energy.

Example 10

Make a rocket countdown.