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”
n ← 1 repeat 4 times: n ← n × 2 say n
coins ← 0
for n from 1 to 10:
if n is even:
coins ← coins + 1
say coinsThe 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