🔁 Unit 2: LoopsSeptember 25, 2016
🎯 Learning Target
I can explain that iteration is the repetition of part of an algorithm until a condition is met or for a specified number of times.
I can create loops in SNAP to reduce the complexity of an existing algorithm.
What is a “loop”? Where have you seen them before?
Redundancy Data that can be left out without loss of function. Repetition. Readability Able to be read. Understandable.
A type of block that causes other code to run multiple times in succession
↑Readability of code
Lab 2.1 - Geometric Fun Times v2.0™
Remember when you drew all those shapes? Didn’t it seem like it should be easier? Well…
In this lab, you will rewrite your SNAP programs from Lab 1.3 to draw shapes using loops.
Section 1 - Back In Time
Open your solution to the original Lab 1.1. Go to the “File” menu and select “Save as…” to give your project a new name.
If your shapes are not already different colors and line-thicknesses, update them now.
Section 2 - Simplifying Code
- Look at your code to draw a square. It is probably quite long and has lots of repeated blocks. Using what you have learned about loops, rewrite this script to be shorter and have less redundancy. Make sure that your code still works as originally intended.
- Now modify your other shape scripts to also use loops. In all cases, try to have as few blocks and as little redundancy as possible while still keeping your code easy to read and understand.
- Do you notice a pattern for the number of sides of a shape, the number of
turn 🔄 ___ degreesfor each shape? Hmm…that’s interesting.
Section 3 - Let’s be lazy.
We’re going to make a block called
shape and make it do all the work for us.
Add code to your program to draw the extra shapes below. Follow all the original guidelines (different color and line thickness for each shape, say the name while drawing) and use loops to keep your scripts as short as possible.
How can you draw a circle? Are you really drawing a circle?