๐Ÿ” Unit 2: Loops

๐ŸŽฏ 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.

Example

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

  1. 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.
  2. 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.
  3. Do you notice a pattern for the number of sides of a shape, the number of repeat and the turn ๐Ÿ”„ ___ 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?