While loop

while repeats a block of code while the condition is true.

General structure#

while condition
  instructions
Indentation

Instructions must have more left margin than the while line.

Basic loop#

n = 0
while n < 5
  print n
  n = n + 1
Watch out for infinite loop

Make sure something inside the block brings the condition closer to false. If n never changes, the program will not terminate.