SAT.AUG.15
2026
22:21:50

For Loops

Tutorial: Find out how to make the turtle do heaps with less code.

Remember

With loops you need to add a colon (:) at the end of the function line. Then you need to indent to the following lines, so the code registers what is part of the loop.

This loop will draw a square without having to type out forward and left 4 times.

for i in range (4):
    forward(100)
    left(90)

num_sides = 7 # adding in extra detail like number of sides
for i in range(num_sides): # this would run the loop 7 times
    t.forward(100)
    t.left(360/num_sides) # divide 360 by 7 to find the right angle

# for spiral shapes you can change out the forward value for i.
for i in range (40):
    forward(i) # this makes the turtle go forward by i,
                # which would be 0 all the way to 40.
    left(90)
Let python do the math!

Python can do math for you - you can leave the equation in the code!

# making a five sized shape
for i in range (5):
    forward (100)
    left(360/5)
  • I can explain how a for loop works.
  • I can make the turtle draw heaps of shapes using only a few lines of code!