📖 Coding lessons · 3 of 4 · 5 min
Loops: repeat without rewriting
A loop repeats instructions. Print the 5 times table:
for i in range(1, 11):
print(5, "x", i, "=", 5 * i)
range(1, 11) gives 1, 2, … 10 (it stops before 11). The indented line runs once for each number.
A while loop repeats while something is true:
count = 3
while count > 0:
print(count)
count = count - 1
print("Go!")
💡 If the condition never becomes false, the loop never ends: an infinite loop!
