If the condition never becomes false, the loop runs forever and your program freezes. Always make sure something changes inside the loop (like count = count - 1) so it can eventually stop.
🛑 break and continue
break — jump out of the loop immediately.
continue — skip to the next time around.
for i in range(1, 10):
if i == 5:
break # stop the loop at 5
print(i)
# prints 1 2 3 4
✅ What you learned
for loops repeat a set number of times, often with range().
for can step through strings and lists.
while loops repeat as long as a condition is true.
break stops a loop; continue skips to the next round.
🎮 Time to Practice!
Let the computer do the boring repetition for you. 🔁
🔢
Task 1: Count to Five
Easy
Use a for loop with range() to print the numbers 1 through 5, each on its own line.
for i in range(1, 6):
print(i)
📣
Task 2: Cheer Squad
Easy
Print Go Team! (with a trailing space) 3 times on one line. Hint: print("Go Team! ", end="") keeps printing on the same line.
for i in range(3):
print("Go Team! ", end="")
⚡
Task 3: Even Numbers
Medium
Print the even numbers from 2 to 10. Two ways to try: use range(2, 11, 2), or loop 1–10 and check % 2 == 0.
for n in range(2, 11, 2):
print(n)
➕
Task 4: Add Them All Up
Tricky
Use a loop to add up all the numbers from 1 to 10 and print the total (it's 55). Hint: start with total = 0 and add each number inside the loop.
total = 0
for n in range(1, 11):
total += n
print(total)
🚀
Task 5: Free Play — Rocket Launch
Creative
Make a countdown using a while loop! Start at 10, count down to 1, then blast off. Add your own emojis and messages.