Python Basics — Loops
Loops
Loops let you repeat code — running a block multiple times without writing it multiple times. They’re one of the most powerful tools in programming.
What You’ll Learn
| Topic | Description |
|---|---|
| For Loop | Iterate over sequences |
| While Loop | Repeat while a condition is true |
| break, continue, pass | Control loop flow |
| range(), enumerate(), zip() | Essential loop helpers |
| Nested Loops | Loops inside loops |
| Practice Exercises | Test your skills |
Why Loops Matter
Without loops, printing numbers 1 to 1000 would need 1000 print() statements. With a loop:
for i in range(1, 1001):
print(i)
Loops are everywhere:
- Processing items in a list
- Reading lines from a file
- Retrying a failed operation
- Running a game until the player quits
- Searching through data
Quick Preview
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I love {fruit}!")
Output:
I love apple!
I love banana!
I love cherry!
Start Learning: For Loop →