Module 04 — Loops: Iteration in Business Analytics#

Graduate MSBA Module Overview

In business analytics, the real power of code emerges when you stop working with individual data points and start working with collections. A loop lets you repeat a block of code automatically across every item in a collection — every customer in a dataset, every transaction in a ledger, every product in an inventory.

Python provides two primary loop types:

  • for loop — iterates through every item in a collection a defined number of times
  • while loop — continues repeating as long as a condition remains true

Loops directly embody the principle of iteration — one of the four core programming principles in this course — and they are the mechanism that makes data processing at scale possible.


Course Connections#

Without loops, you would need to write the same code once for every customer, every transaction, every record. With loops, you write the logic once and Python handles the repetition across any number of records. This is the fundamental shift from manual analysis to programmatic analysis.


Quick Code Example#

customers = [
    {'name': 'Alice Johnson', 'total_spent': 1257.30, 'purchase_count': 12},
    {'name': 'Bob Martinez', 'total_spent': 430.50, 'purchase_count': 4},
    {'name': 'Carol Chen', 'total_spent': 890.75, 'purchase_count': 9},
    {'name': 'David Kim', 'total_spent': 125.00, 'purchase_count': 2}
]

total_revenue = 0
premium_customers = []

for customer in customers:
    total_revenue += customer['total_spent']
    if customer['total_spent'] >= 500:
        premium_customers.append(customer['name'])

average_revenue = total_revenue / len(customers)

print('Total Revenue:', round(total_revenue, 2))
print('Average per Customer:', round(average_revenue, 2))
print('Premium Customers:', premium_customers)

Expected Output:

Total Revenue: 2703.55
Average per Customer: 675.89
Premium Customers: ['Alice Johnson', 'Carol Chen']

Learning Progression#

Platform Student Learning Experience
NotebookLM Explore loops through business storytelling that shows how iteration enables analytics at scale
Google Colab Write for and while loops, combine them with branching, and see how loops process collections of business data
Zybooks Build fluency through structured exercises that reinforce loop syntax, repetition patterns, and practical iteration

Module Pages#

  • Concept → — Deep narrative on loops and iteration at scale
  • Advanced → — Extended code with accumulators and nested loops
  • Notebook → — Jupyter notebook lab description