0

Counting in a loop

  1. set stars to 0
    repeat 3 times
    add 1 to stars
    say stars

    Add 1, again and again

    Add 1 to stars sits inside a repeat 3. The loop goes round three times. So the box ends at 3.

  2. set stars to 0
    repeat 4 times
    move right
    collect the star
    add 1 to stars
    say stars

    Count while you collect

    Each time round, the robot moves, collects a star and adds 1. Four stars, so it says 4.

  3. set stars to 0
    repeat 4 times
    move right
    if on a star
    collect the star
    add 1 to stars
    say stars

    Count only the stars

    Now add 1 sits inside an if block. The robot only counts when it finds a star. Two stars, so it says 2.

  4. repeat 3 times
    set stars to 0
    add 1 to stars
    say stars

    Set to 0 before the loop

    Here set stars to 0 is inside the loop. It empties the box each time round. So the robot only says 1.

  5. Say after the loop

    Put say stars after the loop, not inside. Then the robot waits until all the counting is done.

For parents

Goal: Your child learns to put add 1 inside a repeat so the counting box goes up each time the loop goes round, with set to 0 before the loop and say after it.

  • Ask: how many times does the loop go round? That is often the answer.
  • Have your child keep a tally on paper while the robot runs.
  • Talk about where each block lives: before the loop, inside it, or after it.

Away from the screen: Do jumping jacks together. Before you start, set the count to 0. Each jump, add 1 out loud. When you stop, your child says the final number.

Coding · The Counting Box
Back to top