Skip to content

For Loops

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)
# making a five sized shape
for i in range (5):
forward (100)
left(360/5)

Checklist

  • I can explain how a for loop works.
  • I can make the turtle draw heaps of shapes using only a few lines of code!