PG: Pink box has too many unclear things to be clear. "The FOR block lets you not only repeat, but count the repetitions and /use/ that number to vary the repetitions." Or something.
BH: Hmm, here we have a FOR variable. We should think about whether we can avoid the name "variable" and call it, I don't know, a procedure output?
Teacher feedback from 2017-2018:
On this page, you will use
for loops to repeat and count the repetitions so you can use that counter to draw shapes with repeated patterns:
You've seen these ways to repeat a set of commands:
foreverblock generates an infinite loop that goes on forever. An infinite loop can sometimes be the result of a bug, but in some interactive programs, you want the program to keep running until stopped by the user.
Computer scientists describe a repeating program structure as looping, repetition, or iteration.
The code can be repeated
forever, a specific number of times (such as when using
repeat), or until something specific happens (such as when using
repeat until as you'll see in Lab 5).
Sometimes the script inside a loop needs to know which time through the loop it's in (first, second, etc.).
You can use to keep track, and you can use its counter (the default name is ) in the repeated script. For example, the
for block lets you simplify long scripts like:
Each time the
for block runs the script inside, it changes the value of the counter by 1, beginning with the first input number and ending after the second.
forblock's default counter name, stands for "index." You can change this name by clicking it. To use the counter, drag it into the script.
forblock in the squiral script. What is the result?
moveto get as close as you can get to a smooth spiral:
pause allto debug. Also, there is a comment about this on 2.2.2. --MF, 1/8/20 --MF, 5/26/20
You can use
pause all to place breaks in your code so you can see what's happening along the way. When you run code with
pause all in it, you can click the yellow Run/Pause button next to the Green Flag (/) to move through the code up until a
pause all block is reached again. The
pause all block will pause every script that is running until the yellow Run/Pause button is clicked.
Click for a video that shows how.
nest squaresblock that uses
polygonblock to draw nested squares. Give it an input so that it will draw whatever number of squares you specify, with each square larger than the previous:
nest polygonsthat accepts the number of polygons and the number of sides for the polygons.
pinwheelcode with inputs. Find out how to create your own artistic animations.
The following code may give you ideas about how to create animations. The
warp block allows the drawing of the pinwheel all at once.
forto nest squares this way. Build your block with two inputs that let you specify how many squares the design will contain and how much bigger each square will be than the previous one.
On the right is a painting by Josef Albers. He was interested in experimenting with variations of color within a "family" of similar colors. Snap! will let you make similar experiments.
move, it changes the input to