Tesler:
Instead of having to say left 144 or forward 10, 5 times I can write a procedure
that uses another feature of Logo called Repeat. I can say Repeat five and then give these two
statements only one time and it will automatically make them happen five times. Programmers call
this a loop because it does this and then loops and does it again around and around like a loop.
So let me teach Logo how to star this way and then demonstrate that it really does work, okay we
have a problem — [MISC. DISCUSSION]
Instead of having to write these statements, left forward five times, I can
use a new feature of Logo called Repeat. By saying Repeat five followed by these statement I can
get it to... to do what's called a loop. It will do these statements and then loop around and do
again, around, around, around and it'll do it five times. So let me teach Logo how to star and
then see if it's able to draw the star using this loop instead of ten statements, and right that
worked. Now a programmer would still not be satisfied with this procedure. The problem with it
is that it'll only draw five pointed stars and with just a little more work we could write a
procedure that drew stars with seven, nine, eleven or any...any odd number of sides. If you look
at what makes this star routine always do five pointed stars, it's this number five here and
it's the angle 144 degrees that would be different for a different number of points. So let me
show you another version of the procedure that will work for any odd number of sides. Instead of
five here after the repeat I used what's called a variable and then here instead of 144 I use a
little formula that calculates the proper angle to draw a star with that number of sides. So let
me teach how to draw a star with an arbitrary number of sides and now let me try the program. Go
home, clear the screen—the screen and draw a five pointed star. Oops, I think I've got a bug
here John and the problem is that 360 should have been 180. That's very common in programming is
that you make mistakes. But I'll teach the teach Logo how to do a star the right way and try it
again. Alright, I am, I got a reprieve here. What I want to do now is see if I an draw a star
that has some other number of sides like 13 and now I've shown that yes I've got a procedure
that will draw a star of any number of odd sides. This is the kind of process a programmer goes
through in continuing to generalize and simplify a program. [MISC. DISCUSSION]
I'm afraid I have a bug here John, it's, instead of drawing a five pointed
star it looks like these angles are way too large. I think I know what I did wrong. Instead of
360 here this should have been a 180 only slightly embarrassing but programmers always have
mistakes in their programs and we very well get used to it. Let me teach Logo how to make a star
using the right formula and try it again and see if I've corrected the problem. Yes, now it's
the right formula. And if I've done this right, I should be able to ask it for a star with 13
sides. And it worked.