LESSON 6
Loops
Learning objective: Repeat actions with for and while loops.
Understand
Loops repeat work without duplicating code.
A for loop iterates over a sequence like a list or range(); a while loop repeats while a condition is true. Loops are essential for processing collections of data.
Analogy: A loop is like stamping copies: repeat the same action across many items.
See It in Action
Looping with range:
for i in range(3):
print(i) # 0, 1, 2How it works:
range(3) produces 0, 1, 2, and the loop prints each value in turn.Try It Yourself
- Loop over
range(5)and print each number. - Loop over a list of words.
- Write a while loop that counts down.
Quick Quiz
What does range(3) produce?
Challenge
Print the numbers 1 to 10 using a loop.
Success condition: Your loop prints the full sequence correctly.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →