Grades K–2 · Computing
How does a loop repeat a step and then stop?
A loop tells a character to do the same step again. The step sits inside the loop. Here the inside step is Right: move one square toward the right side of the page.
In the diagramA finite loop repeats its inside stepRepeat 3 timesRight →0123453 rightward moves; finish at 3.The loop stops after its stated number of repeats.
The loop says repeat three times. That means Right, then Right, then Right. Each move counts once. Starting at square zero, the character reaches square three after those three moves.
The loop then stops. Its repeat count has been used up. Writing one step with a count can describe repeated moves without writing a separate copy of every step.
About this explanation
Starting knowledge: Count up to four and follow a one-square page-right instruction.
Sources
- University of Canterbury, CS Unplugged — Kidbots: repetition and loops