๐ Unit 2: Loops
September 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.
Do Now
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.
Loop
A type of block that causes other code to run multiple times in succession
Help with:
โReadability of code
โRedundancy
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
repeat
and theturn ๐ ___ degrees
for 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?