Python · Stage 4 – Repeating Things · Lesson 24 of 50

while Loops

Repeat a block while one condition remains True.

count = 1
while count <= 3:
    print(count)
    count = count + 1
Line-by-line explanation
  1. The counter starts at 1.
  2. The loop continues while count is at most 3.
  3. The current number is displayed.
  4. The final line increases count so the loop can eventually stop.