Raven is making a bead bracelet. "Red, blue, red, blue," she says. Soon she is tired of saying it.
Rocket jumps up. "I have an idea!" he says. "Just say red and blue twenty times."
"That is a loop," Nova says. "A loop repeats a step." Raven smiles. "What do you notice about the pattern?" she asks.
Let's write the bracelet pattern. Then we'll try a clapping loop.
RAVEN was making a beaded bracelet: red, blue, red, blue, red, blue, red, blue. After saying it twenty times Raven got tired. ROCKET said: 'Just say RED-BLUE 20 times.' That is a LOOP.
Write the bracelet pattern below. Repeat RED-BLUE four times.
Now write what REPEAT 6 TIMES of CLAP-CLAP-STOMP looks like.
Rocket wrote clap five times, on five lines. Raven wrote one loop instead.
Both programs make five claps. The loop is shorter to write and easier to change.
LONG WAY
clap
clap
clap
clap
clap
LOOP WAY
REPEAT 5 TIMES:
clap | Statement | True or false? |
|---|---|
| A loop repeats steps. | ? |
| REPEAT 3 TIMES runs its steps 3 times. | ? |
| A REPEAT UNTIL loop always runs 10 times. | ? |
| Loops make programs longer to write. | ? |