Programming with Loops and Variables · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Loops, if-blocks, and variables

Computing · Computing Fundamentals · ages 8-11
Name ______________________   Date ____________
  1. Which block checks something first and only runs its steps when that check is true?

    • repeat block
    • if block
    • variable
  2. Which block lets you repeat steps like 'move' and 'turn' several times without copying them each time?

    • repeat block
    • if block
    • variable
  3. A variable can store a number, like a score, and that number can change while the program runs.

    Circle one:   True   False

  4. A score variable starts at 0. Each time the player collects a coin, the code adds 1 to score. After collecting 5 coins, what is the score?

    Answer: ______________

  5. Leo drew a square by writing 'move, turn' four separate times. Which change would turn this into a loop?

    • if touching edge, move
    • score = score + 1
    • repeat 4 [move, turn]
  6. A sprite has the block 'if touching wall, bounce'. This turn, the sprite is not touching the wall. What happens?

    • It does not bounce, and the program keeps going
    • It bounces anyway
    • The whole program stops
  7. Tom's score is supposed to go up by 1 every time the player scores a goal, but it always shows 0. What is most likely wrong?

    • The loop repeats too many times
    • The if-block's condition is always true
    • The block that adds 1 to score is missing or never runs
  8. Zara wants her cat to say 'meow' ten times, so she copy-pasted the 'say meow' block ten times in a row. What is a better way to write this?

    • Use an if-block that checks the cat's name
    • Use a loop: repeat 10 [say meow]
    • Add a variable called meow
LightMySky · lightmysky.comW1-mt_9x5zgShXPg-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Loops, if-blocks, and variables W1-mt_9x5zgShXPg-s1

  1. if block · An if-block only runs the steps inside it when its condition is true.
  2. repeat block · A repeat block runs the steps inside it more than once, so you only write them one time.
  3. True · That is exactly what a variable is for: a named box that holds a number you can update.
  4. 5 · The variable goes up by 1 for every coin, so 5 coins make the score 5.
  5. repeat 4 [move, turn] · Putting 'move' and 'turn' inside a 'repeat 4' block does the same job without four copies.
  6. It does not bounce, and the program keeps going · The if-block only runs its steps when the check is true, so nothing inside it happens this turn.
  7. The block that adds 1 to score is missing or never runs · If score never changes, the step that updates the variable is probably missing or placed where it never runs.
  8. Use a loop: repeat 10 [say meow] · A loop does the same job as ten copies, and it is easier to change later, like to 'repeat 20'.
Worksheet · LightMySky