Lesson 5

Introducing Loops


In python, we have two main types of loops, called for(): loops, and while(): loops. They are both used to repeat sections of code, but they do it in different ways.

A while(): loop will do a section of code for as long as the condition in the parentheses is true. A condition is any statement that gives a true or false result, for example: a > b, b == a, 4 < 5, etc. If the condition is always true, then the loop will never stop.

A for(): loop will run a set number of times, and then stop.

We want the next part of our code to run forever so we will want to use a while(): loop.

On line 58 , add the following code: while(True):

Hit enter and make sure that the next line is properly indented.

Inside of this loop, we will want to provide our Turtle with some instructions on how to move, just like before. Come up with your own, or copy the code shown on lines 59-62