Overview
A for loop iterates over every item in a sequence, running the body once per item.
Analogy
Flipping through flashcards one by one until the deck is done.
Step-by-step
- for item in iterable: — Python fetches the next item each iteration.
- range(n) generates integers 0..n-1.
- break exits early; continue skips to next iteration.
- else clause runs if loop completed without break.
Visual
for i in range(3): → i=0, body; i=1, body; i=2, body; done
Common mistakes
- Modifying the list you're iterating over (use a copy).
- Off-by-one with range: range(1,n+1) for 1..n.
Practice questions
- Sum all numbers in a list with a for loop.
- Print the multiplication table for 7.
Time
O(n) for n iterations