Skip to content

5. Loops

A loop repeats steps until some condition is met. In a flowchart, this shows up as an arrow that loops back up to an earlier box instead of continuing straight down.

         ( Start )
             |
             v
     +-> < Dishes remain? >
     |     Yes |      \ No
     |         v        \
     +-- [ Wash one dish ]  (  End  )

Pseudocode for a loop uses WHILE ... DO (check first, then act) or REPEAT ... UNTIL (act first, then check):

WHILE dishes remain DO
    Wash one dish

Try it

Draw a flowchart for "keep rolling a die until you get a 6," then write it as a WHILE or REPEAT UNTIL pseudocode block.

Tip

Every loop needs a way to eventually stop. A loop whose condition can never become false is an infinite loop — always double check what makes your loop end.

Next: Variables →