Knowledge organisersIteration
Fix infinite + off-by-one loops.
An infinite loop runs forever because the condition never becomes False. An off-by-one error means the loop runs one too many or one too few times. Both are common bugs.
# Bug: prints 1 to 4 (misses 5)
for i in range(1, 5):
print(i)
# Fix: prints 1 to 5
for i in range(1, 6):
print(i)