6. Loops

Please draw a square 50 points in length using shorthand commands. You will draw the square by moving forward and then turning at a 90 degree angle (a "right angle") to the left.
Draw the square using a sequence (one row) of Logo commands separated by spaces.
You might have felt uncomfortable having to  repeat the same commands over and over. To make it more convenient logo offers the possibility of repeating a list of commands with the use of square brackets. For example, the square you drew before can also be drawn like this:  repeat 4 [ fd 50 lt 90] The number that follows the repeat command represents how many times the command sequence (command list) should be repeated. The command repeat together with the whole command sequence that we choose to repeat is called a loop.
Draw another square that is 100 points long, but this time use a loop
A square has four edges (lines), while an octagon has eight edges. Just as the square’s edges are all the same length, the edges of a regular octagon are also all equal. To draw this octagon we need to tell the turtle to turn in an angle that is half the size of the square's angle.
Draw an octagon. Each edge (line) of the octagon should be 70 points long.
Any command can be done inside a loop. We can even use a loop within a loop. A loop inside another loop is called a nested loop. You can picture the nested loop as a loop that is sitting in a bird's nest of the mother loop. Like this: Command [mama loop [baby loop]].
Before continuing, please clear the screen
The structure or form of nested loops is the same as the structure of the loops we used before. So we can write, for example: penup fd 10 pendown repeat 4 [fd 5 rt 90]
Draw nine squares in one column. The length of each edge (line) of each square will be 5 points. The gap between those squares will be 8 points long.
The command back is pretty similar to forward. The shorthand for the command to go back is bk
Clear the screen, draw a 100 point long line and then move the turtle back to the beginning.
The turtle is back in his place. Now we ask you to draw an asterisk (*) using a loop and back commands. The asterisk should have 20 “arms” instead of the five or six you normally see on a keypad. There are 360 degrees in a circle. So if we want an asterisk made out of 20 lines, we will turn at a 360 / 20 = 18 degree-angle each time.
Draw an asterisk made out of 20 lines. Each line will be 80 points long. Use the turning right command.
Using loops we can easily draw lots of crazy symmetric shapes. This time we will draw 36 octagons in a circle using a double loop (a nested loop). The turn angle will be 360 / 36 = 10 degrees.
Clear the screen and draw 36 octagons with edges that are each 50 points long using two loops.
TurtleAcademy learn programming for freeYour browser is not supporting canvasWe recomand you to use Chrome or Firefox browsers