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}...")
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)
request = server.get_next()
process(request)
Quick Summary
- Use
forloops to traverse collections; usewhileloops for condition-based polling. - Next, we explore Functions & Decomposition to structure scalable software systems.