Ask a Teacher



How to draw a pentagon using repeat command

A nested repeat command is contained inside another repeat command.

Nested repeat commands are a powerful way of using Logo commands.

Here is an example of a nested repeat.

repeat 12 [repeat 5[fd 100 rt 72] rt 30]

 

Explanation of how the above repeat commands work.
repeat 12 [repeat 5[fd 100 rt 72] rt 30]

1. First, Logo does the inner repeat command repeat 5[fd 100 rt 72]. This creates a pentagon.
2. Logo then does the rt 30 at step 2. This turns the turtle cursor right by 30 degrees.
After these two steps, Logo has drawn a pentagon. Logo is now also ready to draw
the next pentagon. 
3. Logo then does steps 1 and 2 again. 
Logo continues to do steps 1 and 2 until it has done them 12 times.
After the 12th time, Logo stops. 




comments powered by Disqus