🔁 Understanding Python Loops: WHILE,
IF, and FOR
🔄 WHILE Loops
A while loop in Python keeps running as long as a condition is true. Once the condition is
false, it stops.
🧊 Icebreaker: While You Clap, I Count!
Tell students: 'You will keep clapping as long as I’m counting!'
Start counting: '1… 2… 3… 4…', and they clap once per number.
Stop suddenly — they stop clapping.
This simulates a while loop — repeated action while a condition holds true.
💬 Real-Life Reflection
Ask: 'What’s something you do every day that repeats until a condition is met?'
Examples: Brushing teeth until clean, scrolling TikTok until bored, etc.
🔹 Python Code Example:
count = 1
while count <= 5:
print("Clap", count)
count += 1
✅ IF Statements
An if statement checks a condition once. If it’s true, it runs a block of code. If not, it skips it.
🧊 Icebreaker: If You Have… Game
Tell students: 'If you're wearing black today, raise your hand!' (etc.)
Only those for whom the condition is true react — just like an if statement.
🧠 Real-World Analogy
Example: If it rains, take an umbrella.
If it's sunny, you do nothing. One check. One possible action.
🔹 Python Code Example:
is_raining = True
if is_raining:
print("Take an umbrella")
🔁 FOR Loops
A for loop in Python is used to repeat a block of code a certain number of times. It helps us
do something to each item in a group (like a list, range of numbers, or characters in a
string).
🎒 Real-Life Analogy: 'Packing Snacks for a Group'
Imagine you have 5 snack boxes to pack for your friends. You go to each one and put in the
same set of items: a banana, a juice, and a sandwich. You repeat the same steps for each box.
That’s how a for loop works!
🔹 Python Example:
snack_items = ["banana", "juice", "sandwich"]
for item in snack_items:
print("Packing:", item)
🔹 Counting Example with range():
for number in range(1, 6):
print("This is box number", number)
📌 When to Use FOR Loops
Use Case For Loop Example
Repeating tasks a fixed number of times for i in range(5):
Looping through items in a list for item in fruits:
Looping through characters in a string for char in 'hello':
📝 Practice Exercises
Try these exercises to strengthen your understanding of loops and conditions in Python:
1. 1. Use a while loop to count from 1 to 5.
2. 2. Write an if statement that prints 'You passed!' if your score is above 50.
3. 3. Use a for loop to print each letter in your name.
4. 4. Use a for loop with if to print only even numbers from 1 to 10.
5. 5. Create a list of 3 hobbies and print them using a for loop.
6. 6. Create a while loop that prints numbers from 10 down to 1.