What if the computer never gets bored?
By the end of this lesson
Predict how many times a repeat-n loop runs, and say why loops beat copy-paste.
Remember
- A loop repeats a block. Computers do not get bored.
- repeat 5 / for i in range(5) runs the body five times.
- A while loop keeps going as long as a condition is true — it must eventually become false.
- Loops match “do this for every student” and “print the 5 times table”.
- Copy-pasting the same print 20 times is how bugs multiply. A loop is one idea, many runs.
Worked examples
Cover the answer. Try the steps on paper, then open them.
Example 1 — Count prints
for i in range(3): print("Hi")
- range(3) gives three turns
- Hi printed three times, each on its own line
Answer: Hi × 3
Check: i is the seat number 0,1,2 unless you use it.
Example 2 — Table
Print the first four multiples of 5 with a loop.
- n goes 1,2,3,4
- each time print 5*n
- 5, 10, 15, 20
Answer: 5 10 15 20
Check: This is the nth-term idea from algebra: 5n.
Example 3 — Danger while
while True: print("Hi") with no break.
- Condition is always true
- It never stops — infinite loop
- You must stop the program by hand
Answer: must have a way out
Check: Finite-ness from the algorithm lesson.
Common mistakes
Slip Thinking range(5) runs when i is 5 (five included) in beginner Python.
Fix range(5) is 0,1,2,3,4 — five numbers, last is 4.
Count how many, or use range(1, 6) for 1…5.
Slip Copy-paste print 10 times, then needing to change the message in 10 places.
Fix One print inside a loop, change once.
That is the point.
Slip A while with no update to the variable in the condition.
Fix If n starts at 1 and you never change n, n < 5 stays true forever.
Update inside the loop.
Try on paper first
Write the answer, then tap Reveal. These are not the quiz — they are warm-ups.
1. How many times does repeat 7 run the body?
Answer: 7
2. Why use a loop instead of 20 pasted lines?
Answer: One change updates all runs; less bugs
3. A loop that never ends is called…
Answer: Infinite loop
4. Printing 3,6,9,12 with 3n is a loop plus what algebra idea?
Answer: nth term / substitution
Touch practice
8 tap / typeTap or type. Use the hint if you need it. Retry any miss — the why is the lesson.
Optional picture lab
After practiceReal world
Clapping 5 times.
Connect
Sequences and tables in maths.
⭐ Star quiz
9 questionsDo the worked examples and touch practice first. Then take the quiz without peeking.