Iteration Simplifies our Turtle ProgramΒΆ

To draw a square we’d like to do the same thing four times — move the turtle, and turn. We previously used 8 lines to have alex draw the four sides of a square. This does exactly the same, but using just three lines:

1
2
3
for i in [0,1,2,3]:
    alex.forward(50)
    alex.left(90)

Some observations:




(turtlesrevised)

Next Section - The range Function