🔁 What are Loops?
A loop allows repetitive tasks in Python. Common loop types are for and while.
📘 For Loop
for loop iterates over sequences like lists, range, etc.
for i in range(1, 6):
print("Number:", i)
Output: Number: 1 to 5
🔄 While Loop
The while loop continues as long as the condition is true.
count = 1
while count <= 5:
print("Count is", count)
count += 1
⚙️ Loop Control Statements
break– Exit the loop earlycontinue– Skip current iterationpass– Do nothing (placeholder)
for i in range(5):
if i == 3:
break
print(i)
✅ Real-Life Examples
- Looping through shopping cart items
- Repeating a password prompt
- Processing a file line-by-line