RisingCoder Full course โ†’
Day 1Day 2Day 3Day 4
๐Ÿ”
STUDENT NOTES ยท DAY 5 OF 24

The Repeat Machine ๐Ÿ”

Why type something 100 times when Bittu can repeat it for you? Today: for loops, while loops, and the mighty break.

1The for loop โ€” repeat a fixed number of times

๐Ÿ
Py: A for loop is like roll-call: go through the numbers one by one, do the same thing for each.
๐Ÿฆ‰
Professor Hoot: range(1, 6) gives 1,2,3,4,5 โ€” the end number is never included. It's shy.

Range visualizer โ€” slide the end number!

range(5)
0  1  2  3  4

2Loops do real work

Remember writing multiplication tables in a notebook? Two lines of Python:

๐Ÿค–
Bittu: Table of 7 in 0.0001 seconds. Ask me for the table of 40404 โ€” I don't care.

3The while loop โ€” repeat UNTIL something changes

A while loop doesn't count โ€” it keeps going as long as its test stays True:

๐Ÿž
Bugly: Heheheโ€ฆ forget the count = count - 1 line and the loop runs FOREVER. My favourite trap! (Press the stop โ–  button in Colab if it happens.)

4break โ€” the emergency exit

๐Ÿ
Py: while True loops forever on purpose โ€” until break smashes the exit. Every game loop ever is built like this.

5Quick quiz! ๐Ÿง 

What is the LAST number printed by for i in range(1, 6): print(i)?
๐Ÿ’ก range(1, 6) stops BEFORE 6. Prints 1,2,3,4,5.
A while loop's test never becomes False. What happens?
๐Ÿ’ก Nothing stops it! Something inside the loop must change, or you meet the infinite loop.

6Your mission ๐Ÿš€

Mission 1: Print your name 10 times with a for loop.
Mission 2: Print the table of any number the user types (input + int + loop).
Mission 3: Make a countdown from 10 to 1 that ends with "๐Ÿš€ LIFTOFF!".

Day 5 done โ€” you command the Repeat Machine! ๐Ÿ”

Next: loops inside loops, skipping with continue, and star pyramids.

Go to Day 6: Loop Tricks โ†’

๐ŸŽฎ Or test yourself in the Python Arcade โ†’