Rocket types a short program for Nova. "Repeat five times, say hi," he reads. Nova says hi five times, then stops.
"What do you notice about the number?" Raven asks. "It tells Nova how many times."
Next, Rocket puts a loop inside a loop. Some loops even run until something happens.
Let's read each loop and count what it does.
Computers write loops in short code. Read the pseudocode below:
REPEAT 5 TIMES:
print 'Hi!' REPEAT 3 TIMES:
clap
stomp REPEAT 4 TIMES:
REPEAT 2 TIMES:
jump Some loops don't know how many times. They just go UNTIL something happens. Read this:
REPEAT UNTIL the cup is full:
pour 1 spoon of water If the cup holds 8 spoons, how many times does this loop run?
(a) 1 (b) 8 (c) Forever
Now write a REPEAT UNTIL loop for filling a backpack with books until it is heavy.