ITERATION

LESSON #2 - Iteration
Initial lesson posting - July, 2011 Revision date - Fall 2017


 * Purpose: ** This lesson introduces the idea of iteration. Iteration is the act of doing the same thing over and over again.
 * Essential Question: ** How do you create a Logo design with the Repeat command?

A Section of the Lesson Follows

In the first lesson, you drew segments that looked like spokes of a wheel. You may have gotten really tired of typing the same set of commands over and over again. When this happens, it makes sense to use the repeat command. The repeat command needs two items, the number of repeats and a list of commands or “instructions” that need to be repeated.
 * New Command: **

For example, the command to walk forward 100 steps, backwards 100 steps, and then turn and do it again is written out below in words, and then in Logo code. repeat 2 [walk forward 100 steps walk backwards 100 steps turn right 90 degrees] repeat 2 [fd 100 bk 100 rt 90] The general format is: repeat number [repeated instructions] ** Caution: ** Do NOT use commas between any of the commands in the brackets. ** LESSON 2 - TASK 1 ** Predict what will happen if you type the following commands into Logo. Then, use Logo to confirm your prediction. Clear the graphics window between each problem by typing CS. You can clear the listener window by typing CT. A. repeat 4 [fd 100 bk 100 right 90] B. repeat 8 [fd 100 bk 100 right 45] C. repeat 12 [fd 100 bk 100 right 30] D. repeat 10 [fd 100 bk 100 right 36] ** LESSON 2 - TASK 2: ** There is a common pattern in each of the repeat commands above. Describe this pattern. Write a repeat command that will draw 20 evenly spaced spokes. See the end of this lesson for discussion of this task.

** New Commands: ** The **stamp** command stamps the image of the turtle into the graphics window. The image will face in the same direction as the icon.

The **lockshape** command will prevent the turtle icon from rotating in the graphics. Lockshape can be used with the stamp command. CAUTION – the shape will be locked to the turtles most current heading! Use **unlockshape** to allow the turtle’s icon to rotate. The **turtletext** (or **tt**) takes a word or a list as input and writes it in upper case at the turtle’s current location. The text is orientated from left to right so you can read it. In Terrapin Logo, the **shapes panel** or the **setshape** command changes the turtle’s icon to a different shape. Please read the Reference Manual or use the Help Menu to learn how to change the turtle’s shape.

Logo code for a ten spoke wheel with a train stamp at the end of each spoke (this graphic is not in the lesson). Lockshape repeat 10 [fd 100 stamp bk 100 rt 36]

**Lesson 2 - Task 3** (second graphic) See if you can write the Logo code on your paper, then test it on your computer.