Tuesday, October 18

REPEAT command in Logo

Today we will cover a new command in Logo called REPEAT.  This command allows the user to simplify drawing shapes by telling Logo to REPEAT a direction a stated number of times.  For example, if you are drawing a square, you are really just drawing the same thing four times in Logo (fd 100 rt 90 fd 100 rt 90 fd 100 rt 90 fd 100 rt 90).  Instead of typing in the same thing 4 different times we can tell Logo to REPEAT the directions we give it - in the case of a square we would want it repeated 4 times.

When using the REPEAT command there are several things to keep in mind.  First, there is no abbreviation for the REPEAT command, so you'll have to just type in REPEAT.  Second, when using the REPEAT command you need to first tell Logo how many times you are going to repeat something; then you'll need to enter the instructions you want Logo to repeat in brackets (they look like this  [  ], and are found above the Return key on your keyboard ).

REPEAT statements in Logo can be written in several ways - statements can be only REPEAT commands, they can contain REPEAT commands, they can have multiple REPEAT commands, or REPEAT commands can be inside other REPEAT commands (this is called nesting, and is an advanced concept in programming).  In other words, I can create a square using only a REPEAT command.  Do the following:  REPEAT 4 [fd 50 rt 90].  This will create a square.  Now, try this in Logo (clear your screen first):  fd 50 REPEAT 4 [fd 50 rt 90] .  You should get something that looks like the letter P.

Logo reads the information in a REPEAT statement by knowing that when it sees REPEAT, its going to repeat the instructions inside the brackets the number of times that are listed after the word REPEAT.  For our square example above, Logo will repeat the instructions in the brackets - [fd 50 rt 90] - 4 times.

As a reminder, the crossword puzzle is due on Thursday - don't forget to get that completed and handed in.  You are welcome to turn that in early if you want.

Vocab quiz #5 (Internet #1) is on Friday, Oct. 21.  If it's your week to define words get that done first in class today instead of the work we are doing!

No comments:

Post a Comment