Repeat Until the Task Is Done
Scenario
A library volunteer labels three books. Each pass labels one unlabelled book.
- 1Three books left
- 2Two books left
- 3One book left
- 4Zero books left
Try it yourself
Predict how many passes occur before the loop stops.
- Three books left
- Two books left
- One book left
- Zero books left
Check again while books remain
Unlabelled books after this step 3
Reveal the explanation
- Three books left
Label one. Two remain.
- Two books left
Label one. One remains.
- One book left
Label one. Zero remain.
- Zero books left
Stop. The loop body runs three times.
Try starting with zero books. If the condition is checked first, the loop body runs zero times.
Your turn
Trace the loop for zero books and for two books, including the final check.
Common mistake Repeating an action without changing the condition.
Check your work
Two traces show zero and two iterations. Both end with zero books left.
This browser could not save your progress. Changes last until you leave the page.