4 min read
while Loops
Prerequisites: Loops
A while loop keeps running its block as long as a condition stays
True — used when you don't know in advance how many times you'll need
to repeat.
count = 0
while count < 3:
print(count)
count += 1
Expected output
0
1
2
Common mistakes
- Forgetting to update the loop's condition variable (
count += 1above) — this creates an infinite loop that never stops.