steps = 0Start at 0
The robot wants to count its steps. First it makes a box with 0 inside. Nothing is counted yet. A box used this way is a counter.
- set steps to 0repeat 3 timesadd 1 to stepssay steps
Add 1 each turn
Put steps = steps + 1 inside a loop. Each turn adds 1. The loop runs 3 times, so steps ends at 3. say(steps) runs once, after the loop.
10 start 21 turn 1 32 turn 2 43 turn 3
Watch the box
Write the number after each turn. It goes 0, then 1, 2 and 3. The last number is what the robot says.
- set steps to 0repeat 4 timesmove rightadd 1 to stepssay steps
The robot counts as it walks
Now the loop has two lines inside. Each turn, the robot moves right and adds 1. It walks 4 squares, so it says 4.
say after the loop says 3 once say inside the loop says 1, 2, 3 Where say goes
Where you put say matters. After the loop, it says one number at the end. Inside the loop, it says a number every turn.
For parents
Goal: Your child learns to use a loop to add to a variable, and to tell the number it ends on.
- Have your child write the number in the box on paper after each turn of the loop.
- Ask: is say inside the loop or after it? How many numbers will it say?
- The labs ask your child to predict a count, fix a broken counter, then build one. Ask where each block lives: before, inside or after the loop.
Away from the screen: Act out claps = 0, then repeat 4: clap and add 1. Your child claps and counts out loud, then says the final number.