Skip to main content
CodeFlow
all algorithms
algorithm 01

Loops

Repeat the same idea until the work is done. Three flavours, one metaphor: a courier with a stack of letters and a row of mailboxes.

01 / Loops

Deliver to every mailbox, in order.

n =
#0#1#2#3#4
i
condition
iter
0
body
0
delivered
0
step 0
  1. 0def deliver_all(n):
  2. 1 for i in range(n):
  3. 2 deliver(i)
  4. 3 return
Click Run to play the steps.

What you just watched

All three loop forms produce the same outcome — a delivery to every mailbox — but they make different promises about when the condition is checked. for and while check first. do-while runs the body first, then checks. Try n = 0 on the do-while variant to see the surprise.