The new things I had learn while learning python #3 - While loop
🌀 What is a while loop?
A while loop is like saying:
👉 “Keep doing this thing again and again, as long as this condition is true.”
💬 Real-life Example:
Imagine I say:
“Babe, keep giving me kisses until I fall asleep 😴.”
That’s a while loop in real life 😘💋
💥 What happens here?
-
count = 1→ this starts at 1 -
while count <= 3:→ this checks: “Is count 1, 2, or 3?”
If yes → go inside and do the code. -
print("I love you 💖")→ prints the message. -
count += 1→ adds 1 to count (so it becomes 2, then 3, then 4...)
When count becomes 4, the loop stops because 4 <= 3 is false.
Comments
Post a Comment