Only Boring People Get Bored

Imagine if your teacher asked you to write โI will not talk in classโ 100 times on the blackboard. You would hate it. Your hand would hurt. You would make mistakes.
A computer? It would love it. It can do it in a blink of an eye. โก
Human way (terrible!):
print("I will not talk")
print("I will not talk")
print("I will not talk")
...98 more times... ๐ซ
Computer way (brilliant!):
for i in range(100):
print("I will not talk")
Done in 0.001 seconds! ๐
The for Loop
In Python, when we want to repeat something, we use a loop.
for i in range(3):
print("Python is fun!")
Output:
Python is fun!
Python is fun!
Python is fun!
Breaking it Down
for: Start the loop.i: A variable that counts for us (0, 1, 2โฆ).in range(3): How many times? 3 times.:: Donโt forget the colon!- Indentation: The lines pushed in are the ones that get repeated.
๐ Try This NOW!
What will this print?
for i in range(5):
print("Hooray!")
Click to check!
It will print "Hooray!" exactly 5 times!Using the Counter
The variable i changes every time the loop runs. You can use it!
for i in range(5):
print("Countdown:", i)
Output:
Countdown: 0
Countdown: 1
Countdown: 2
Countdown: 3
Countdown: 4
Wait, why does it start at 0? Computer scientists count from 0. Itโs just a quirk we love. (0, 1, 2, 3, 4) โ that is still 5 numbers!
๐ฎ Real-World Connection
This is how TikTok shows you videos one after another! It has a list of videos and loops through them: for video in video_list: show the video! Every social media app uses loops to display content!
Making a Pattern
Loops are great for art.

text = "*"
for i in range(5):
print(text)
text = text + "*"
Output:
*
**
***
****
*****
Cool, right? We made a triangle!
Challenge: Make it Backwards!
Can you make the triangle upside down? (Start with 5 stars, end with 1)
Loops with Variables
You can do math inside a loop! Letโs count how many steps we take.
steps = 0
for i in range(5):
steps = steps + 1
print("I have taken", steps, "steps")
Output:
I have taken 1 steps
I have taken 2 steps
I have taken 3 steps
I have taken 4 steps
I have taken 5 steps
Or we can add up numbers:
total = 0
for i in range(1, 6): # Numbers 1 to 5
total = total + i
print("Adding", i, "Total is now:", total)
print("Final total:", total)
Output:
Adding 1 Total is now: 1
Adding 2 Total is now: 3
Adding 3 Total is now: 6
Adding 4 Total is now: 10
Adding 5 Total is now: 15
Final total: 15
Stopping Early (The Emergency Brake)
Sometimes you want to stop the loop before it finishes. We use the command break.
Imagine you are looking for a lost key. Once you find it, you stop looking!
for i in range(100):
print("Looking in box", i)
if i == 5:
print("FOUND IT!")
break
Output:
Looking in box 0
Looking in box 1
Looking in box 2
Looking in box 3
Looking in box 4
Looking in box 5
FOUND IT!
The computer will stop at box 5, even though the range was 100!
Try It Yourself
Challenge 1: Write a loop that prints โHappy Birthday!โ 10 times.
Challenge 2: Write a loop that counts down from 10 to 1.
(Hint: range(10, 0, -1) counts backwards!)
Challenge 3: Write a loop that adds up all numbers from 1 to 10. Print the final total.
Solution to Challenge 2:
for i in range(10, 0, -1):
print(i)
print("Blast off! ๐")
Common Mistakes & Fixes
โ Wrong: for i in range(5)
print("Hi")
Why it fails: Missing the : at the end!
โ
Right: for i in range(5):
print("Hi")
Always add the colon!
โ Wrong: for i in range(5):
print("This")
Why it fails: Not indented!
โ
Right: for i in range(5):
print("This")
Indent the code you want to repeat!
โ Wrong: for i in range(0):
Why it fails: Range of 0 means zero times!
โ
Right: for i in range(5):
The number should be how many times you want!
๐ Bug Hunter Betty Says:
โIf your loop runs forever and wonโt stop, press Ctrl+C (or Command+C on Mac) to stop it! Then check: did you forget to use range()? Did you accidentally create an infinite loop?โ
๐ Achievement Unlocked: Loop Master! Wizard Level: Sorcerer (5/10 complete)
๐ Todayโs Spell Book (Quick Reference)
for i in range(5): # Repeat 5 times (0,1,2,3,4)
print("Hi")
for i in range(1, 11): # Count from 1 to 10
print(i)
for i in range(10, 0, -1): # Count backwards from 10 to 1
print(i)
# Breaking out early:
for i in range(100):
if i == 10:
break # Stop the loop!
๐ก Parent/Teacher Tip
If your learner creates an infinite loop by accident (one that never stops), calmly show them how to stop it with Ctrl+C. Explain that even professional programmers do this sometimes! Then help them find why itโs looping foreverโusually itโs a while True: without a break, or forgetting to change the counting variable.
In the next lesson, weโll learn how to handle errors like a pro!
This post is part of the Python Basics for Kids series, based on โPython for Kids from 8 to 88โ.