Loops help repeat tasks automatically — very important for data processing and automation.
🔹 1. What are Loops?
Loops repeat a block of code multiple times.
👉 Used in:
✅ Data cleaning
✅ Data analysis
✅ Machine learning
✅ Automation
🔥 2. for Loop (Most Used) ⭐
Used to iterate over a sequence (list, string, range).
✅ Basic Syntax
for variable in sequence:✅ Example — Print Numbers
# code
for i in range(5):Output: 0 1 2 3 4
print(i)
👉 range(5) → generates numbers from 0 to 4.
✅ Loop Through List (Very Important)
numbers = [10, 20, 30]👉 Used heavily in data science.
for num in numbers:
print(num)
🔥 3. while Loop
Runs until condition becomes False.
✅ Syntax
while condition:✅ Example
# code
x = 1Output: 1 2 3 4 5
while x <= 5:
print(x)
x += 1
👉 Important: Update condition to avoid infinite loop.
🔹 4. Loop Control Statements (Very Important)
✅ break → stop loop
for i in range(5):Output: 0 1 2
if i == 3:
break
print(i)
✅ continue → skip current iteration
for i in range(5):Output: 0 1 2 4
if i == 3:
continue
print(i)
🎯 Today’s Goal
✅ Use for loop
✅ Use while loop
✅ Understand break & continue
Double Tap ♥️ For More