Loops
Prerequisites: Conditions
A loop repeats a block of code, either a fixed number of times or until a condition is no longer true — instead of copy-pasting the same instruction over and over.
Real-world analogy: a loop is like "do 20 push-ups" instead of writing out "do a push-up" twenty separate times.
for number in [1, 2, 3, 4, 5]:
print(number)
Common mistakes
- A loop with a condition that never becomes false runs forever (an "infinite loop") and freezes the program.