A for loop repeats instructions a set number of times, in this case 8 times. A for loop has an associated variable (called i here).
In this example, i starts from 0 and increases by 1 each time. Let's apply this to the code to draw a square:
from turtle import Turtle, Screen
turtle = Turtle()
for i in range(4):
turtle.forward(100)
turtle.right(90)
Copy and paste this code into the Trinket editor above and run it. The turtle has been asked to repeat two instructions four times to make a square.
Once you have created one shape using a loop, you can repeat the shape again and again by putting it inside another loop. This is a great way to
draw spirals. A spiral can be made by turning a small degree and then moving forward a small amount. The section of code for making a square is inside another
for loop that repeats it 30 times, each time turning the cursor 25 degrees to make a pleasing spiral shape.Adapt your code by making it look like this:
from turtle import Turtle, Screen
turtle = Turtle()
for i in range(30):
for i in range(4):
turtle.forward(100)
turtle.right(90)
turtle.right(25)
Try to complete each of these challenges: 1. Alter the for loop so that it draws a more interesting spiral using one of the shapes you made earlier,
like a triangle or circle? 2. Adding a few extra lines where you alter the variables R, G, and B would allow you to make a multicoloured spiral.