8 min read Beginner Lesson 3 of 11
Part 1 — Thinking Like a Programmer

Loops & Iteration

Computers excel at doing repetitive tasks millions of times without fatigue. Loops allow you to express vast iterations with just two lines of Python code.

Processing 100,000 Transactions in 20 Milliseconds

A human checking 100,000 bank records by hand would take months. A Python for transaction in ledger: loop executes in milliseconds because the CPU can fetch and increment index counters billions of times per second.

`for` Loops vs `while` Loops

1. `for` Loop (Definite Iteration)

Iterates through a known collection (lists, strings, ranges).

for item in ["CPU", "RAM", "SSD"]:
    print(f"Checking {item}...")
2. `while` Loop (Indefinite Iteration)

Runs continuously until a dynamic condition becomes False.

while server.is_active():
    request = server.get_next()
    process(request)

Quick Summary

  • Use for loops to traverse collections; use while loops for condition-based polling.
  • Next, we explore Functions & Decomposition to structure scalable software systems.