Two hops, a turn right, then four hops reach the star.
The big ideaA counting loop repeats a set number of times, counting up each round.
How it works
A counting loop repeats a set number of times.
A counter starts at zero and goes up by one each time round.
When the counter reaches your number, the loop stops.
Change the number to change how many times it repeats.
One counting loop.
Example 1: Five hops
The course has five posts, so the program says repeat 5 times: hop.
Bo hops one, two, three, four, five, and the counter reaches 5.
The loop stops and Bo is on the flag.
A counting loop for five posts.
Example 2: Change one number
The flag moves farther away, so there are 9 posts.
Mina does not rewrite the program. She changes the 5 to a 9.
Bo hops 9 times and stops on the new flag.
Example 3: One hop too many
Teo miscounts the posts and writes repeat 6 times for a course of 5 posts.
Bo makes 6 hops, which is one more than 5.
He bumps into the fence. The mix-up to fix: change the 6 to a 5.
Example 4: Get Bo to the star
Bo starts at the bottom left, facing up. The star is at the top right.
Forward 2 times brings him to the top row. Turn right makes him face along the row.
Forward 4 times then brings him to the star. That is 3 blocks, because the counters do the work.
Bo's route to the star.
Words to know
counting loop
A loop that repeats a set number of times.
counter
A number that starts at zero and goes up by one each time round.
repeat
Do the steps inside again.
Watch out
Count the posts carefully. One number too big or too small is a bug.
The counter starts at zero, not one, but the loop still makes exactly the number of hops you wrote.
To change the course, change the number. You do not need to rewrite the program.
A turn needs its own block. Counting only makes Bo go straight.
Try it
A loop says repeat 8 times: hop. How many hops does Bo make?
Where does the counter start?
A loop says repeat 3 times: hop, beep. How many beeps?
The loop says repeat 9 times: hop. After it, Bo hops 4 more times. How many hops in all?
There are 5 posts but the loop says 7. Is the number too big or too small?
Answers: 1. 8 · 2. At zero · 3. 3 · 4. 13 · 5. Too big
Try at homeClap or hop with a grown-up and count out loud as you go. Pick a number first, like seven, and stop when you reach it. Then change the number and go again, and you have made a counting loop with your body!
For grown-upsDo the Mission: pick a number like seven, then clap or hop while counting out loud and stop when you reach it. Change the number and go again, and you have made a counting loop with your body.
Open these notes on screenScan the code, or go to tutorpip.com.