World 2: Loops
Long roads
- The roads are longer now. Ten
rightlines? Too many! - A loop repeats lines for you.
Words for this world
| Word | Meaning |
|---|---|
| loop | code that runs again and again |
| repeat | do the same thing one more time |
| pattern | moves that come again in the same order |
Repeat a move
- Everything inside the loop repeats.
- Find the pattern on the map, then put it inside the loop.
DECLARE i : INTEGER
FOR i ← 1 TO 3
OUTPUT "right"
NEXT i
OUTPUT "down"
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
Home is 10 squares to the right. Do not write 10 lines: use a loop.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
Walk down the stairs: right, down, right, down… Repeat the two moves with a loop.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
Every second square has a star. Use a loop that moves right two times on each turn.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Find the pattern: right, right, down. Repeat it with a loop.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Go right to the end, down two squares, then left all the way home. Use a loop for each long walk.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Walk around the garden and collect all 4 stars. Home is just below the start, so you finish there.
Cliquez sur Exécuter pour voir le résultat ici.