Skip to main content

Command Palette

Search for a command to run...

πŸ” Loops Explained Like You're 5

Published
β€’1 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

A repeating alarm clock

Day 23 of 149

πŸ‘‰ Full deep-dive with code examples


The Alarm Clock

Your alarm rings every morning at 7 AM.

It doesn't ring once and forget. It repeats every day!

Loops are code that repeats!


Without Loops (Painful)

print("Hello 1")
print("Hello 2")
print("Hello 3")
print("Hello 4")
print("Hello 5")
# ... 95 more lines 😫

With Loops (Easy!)

for i in range(100):
    print("Hello", i)

Done in 2 lines! πŸŽ‰


Types of Loops

For Loop: "Do this exactly 10 times"

for i in range(10):
    print(i)

While Loop: "Keep doing this until something changes"

while hungry:
    eat_snack()

In One Sentence

Loops repeat code automatically instead of you copying and pasting the same thing over and over.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

More from this blog

esreekarreddy

132 posts