maddyhelps

Grade 6 · Printables

Loops and conditions

Reading code. Part of how things work.

All sheets

Loops and conditions

Reading code · Alberta Grade 6 · maddyhelps.com

Name
Date

Follow each program one line at a time, keeping track of the numbers in the box beside it. Then use a loop to shorten the robot's program.

score ← 0
repeat 5 times:
  score ← score + 3
if score > 12:
  say “Level up!”
otherwise:
  say “Keep going”
It says
n ← 1
repeat 4 times:
  n ← n × 2
say n
It says
coins ← 0
for n from 1 to 10:
  if n is even:
    coins ← coins + 1
say coins
It says

The robot's program: forward 2, turn right, forward 2, turn right, forward 2, turn right, forward 2, turn right.

Rewrite it with a loop. What shape does it draw?

One way computers make life better, and one problem they cause

For the grown-up

Loops and conditions

Program 1: score ends at 15, so it says “Level up!”. Program 2: 16. Program 3: 5 (2, 4, 6, 8 and 10). The robot: repeat 4 times: forward 2, turn right — a square. Replacing repeated steps with a loop is abstraction: seeing the pattern and naming it once.

Program 1 is the one to check: if a child stops the loop at 12, they will say “Keep going”. The condition is greater than 12, and 15 is.

Why this matters is on the how things work page. More sheets