Loops and Iterations
Loops help automate repetitive work — instead of doing the same thing over and over manually. Business analysts use loops every day to scan rows of data, generate reports, clean messy inputs, and check rules across multiple items.
Estimated reading time: 15–20 minutes
Useful Loop Patterns
- for … in → repeat work for each item in a list
- range() → do something a set number of times
- enumerate() → get item AND its position
- zip() → loop multiple lists together
Great for: walking through tables, lists, or user inputs
Flow Controls
- break → stop early when a rule is met
- continue → skip invalid or unwanted values
- pass → placeholder while planning logic
Great for: cleaning messy business data
For Loops — Work Through Items One by One
Imagine checking every row in Excel manually — that’s not scalable 🔁 A for loop lets you apply a rule to each element efficiently.
for letter in "Python":
print(letter)Here’s how to loop with numbers, positions, and multiple lists:
data = ["Draft", "Review", "Published"]
for i, status in enumerate(data, start=1):
print(i, status)
owners = ["Ana", "Bob"]
tasks = [3, 5]
for name, count in zip(owners, tasks):
print(name, "has", count, "tasks")Business insight: Instead of clicking through dozens of rows, a loop checks all of them — perfectly, every time ✅
While Loops — Repeat Until Something Changes
While loops are great when you don’t know how many times something should repeat, but you know the stop condition.
count = 1
while count <= 3:
print("Step", count)
count += 1Common use: keep asking a user for valid input
Break & Continue — Control Loop Flow
These help write cleaner business rules.
Example: skip incomplete values (continue) or stop when a risk is found (break).
for x in range(10):
if x == 5:
break
if x % 2 == 0:
continue
print(x) # just odd numbers < 5Analyst tip: Use continue instead of writing many nested if statements ✅
Mini Example — Summing a List
Great first automation: replacing Excel SUM() with a loop.
numbers = [10, 20, 30]
total = 0
for n in numbers:
total += n
print("Total:", total)Cornerstone Project — Stand-Up Helper: Agenda + Nudges
A real office tool: before a team stand-up, run this to highlight what needs attention — blocked work and reminders. You’ll impress by making meetings more productive 📈
Step 1 — Create a tiny task board
Think of this like a few Jira / Trello cards.
tasks = [
{"title": "Fix data pipeline", "owner": "Ana", "status": "blocked"},
{"title": "Weekly report prep", "owner": "Bob", "status": "todo"},
{"title": "Customer call notes", "owner": "Cara", "status": "in_progress"},
{"title": "Data cleanup", "owner": "Ana", "status": "todo"},
]Step 2 — Build a talking-point agenda
Loop twice: first for blockages (critical), then todo work.
agenda = []
for t in tasks:
if t["status"] == "blocked":
agenda.append("🔴 BLOCKED: " + t["title"])
for t in tasks:
if t["status"] == "todo":
agenda.append("🟡 TODO: " + t["title"])
print("Agenda:")
for item in agenda:
print(" •", item)Why this works: You are automatically prioritizing discussion ✅
Step 3 — Generate a small nudge list
We only remind people when needed (uses continue).
nudges = {}
for t in tasks:
if t["status"] != "todo":
continue
owner = t["owner"]
nudges[owner] = nudges.get(owner, 0) + 1
print("\nNudges:")
for owner, count in nudges.items():
print(f" • {owner}: {count} follow-ups needed")Real-world benefit: You help the team stay accountable ✅
Optional Upgrade — Limit meeting length with break
Stand-ups should be short ⏱
short = []
for item in agenda:
short.append(item)
if len(short) == 3:
break
print("\nShort agenda:")
for line in short:
print(" •", line)You just created a real-world meeting optimization assistant using loops 🎯
Key Takeaways
- for = best for business data and task lists
- while = runs until a stopping condition
- break/continue keep logic clean and focused
- Small loops can automate real-world office workflows 🎉
Next Up: You’ll learn functions — which turn this into a reusable product!