Math Bonk! Learning Centre Play the game

Worksheet for the lesson Coding with Loops, Conditions and Efficient Code · All worksheets

Coding with Loops, Conditions and Efficient Code

Grade 5 math worksheet · mathbonk.com/learn

Name: ______________________   Date: ____________

Look

A grid of stamps that is 6 rows tall and 2 columns wide, with arrows showing an outer loop and an inner loopinner loop: 2 timesouter loop: 6 times
  1. repeat 6 [repeat 2 [stamp]] makes this grid. How many stamps in all?
  2. Swap the loops: repeat 2 [repeat 6 [stamp]]. How many stamps now?
  3. How many stamps are in each column?

Practice

  1. repeat 5 [ forward 3 ] moves the pen how many squares in total?
  2. repeat 4 [ repeat 3 [ forward 1 ], turn ] moves forward how many squares in total?
  3. How many lines does "forward 2, turn" written out four times take?
  4. Rewrite with a loop: forward 6, turn, forward 6, turn, forward 6, turn, forward 6, turn
  5. What shape does "repeat 4 [ forward 5, turn ]" draw?
  6. "repeat 4 [ forward size, turn ]" with size set to 6 draws a square with what perimeter in squares?
  7. Which command helps code decide between two paths: repeat, if or turn?
  8. A program says: set steps to 4, then repeat 6 [ forward steps ]. How far does it go?
  9. A program says: set steps to 7, then repeat 6 [ forward steps ]. How far does it go?
  10. A robot code has a bug: it repeats "forward 3" 5 times but should go 12 squares. What should the repeat number be?

Think it through

  1. Draw the path drawn by repeat 3 [forward 4, turn right 120°].
  2. Explain why a loop is better than writing a command out many times.

Challenge

  1. How many commands are in repeat 5 [repeat 2 [forward, turn, stamp]]?
  2. A bug: repeat 6 [forward 2] moves 12 squares but should move 18. What could you change?

Answer key

Look

  1. 12
  2. 12
  3. 6

Practice

  1. 15
  2. 12
  3. 8
  4. repeat 4 [ forward 6, turn ]
  5. a square
  6. 24
  7. if
  8. 24 squares
  9. 42 squares
  10. 4

Think it through

  1. An equilateral triangle
  2. It is shorter, easier to read and easy to change

Challenge

  1. 30
  2. Repeat 9 times, or forward 3 each time