Coding with Loops, Conditions and Efficient Code
Grade 5 math worksheet · mathbonk.com/learn
Name: ______________________ Date: ____________
Look
- repeat 6 [repeat 2 [stamp]] makes this grid. How many stamps in all?
- Swap the loops: repeat 2 [repeat 6 [stamp]]. How many stamps now?
- How many stamps are in each column?
Practice
- repeat 5 [ forward 3 ] moves the pen how many squares in total?
- repeat 4 [ repeat 3 [ forward 1 ], turn ] moves forward how many squares in total?
- How many lines does "forward 2, turn" written out four times take?
- Rewrite with a loop: forward 6, turn, forward 6, turn, forward 6, turn, forward 6, turn
- What shape does "repeat 4 [ forward 5, turn ]" draw?
- "repeat 4 [ forward size, turn ]" with size set to 6 draws a square with what perimeter in squares?
- Which command helps code decide between two paths: repeat, if or turn?
- A program says: set steps to 4, then repeat 6 [ forward steps ]. How far does it go?
- A program says: set steps to 7, then repeat 6 [ forward steps ]. How far does it go?
- 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
- Draw the path drawn by repeat 3 [forward 4, turn right 120°].
- Explain why a loop is better than writing a command out many times.
Challenge
- How many commands are in repeat 5 [repeat 2 [forward, turn, stamp]]?
- A bug: repeat 6 [forward 2] moves 12 squares but should move 18. What could you change?