You will have noticed that with your
turtle drawings, you are often repeating the same commands over and
over. Loops can help you avoid having to write the same code.
Here is a program for you to try out:

 |
| Count is a variable. It is
just a container for storing things. You could use any other
name besides count eg x, i, fred, bananas. In this case it
stores the number of the loop.
Range is the number of times Python will go through the loop.
You can see the values Python uses for range by typing range(4)
directly into the IDLE command window. You should get
[0,1,2,3]
The body of the loop must be indented. Indenting tells
Python which lines of code belong to the loop.
|
|
Now try these:
 |
| Python is very fussy about where you start
your lines. If you are making a loop, you must indent each
line in the body of the loop 4 spaces (or 1 tab). If you have
a loop inside a loop, then it has to be indented 4 more spaces. |
|
 |
| By putting loops inside loops you can do
some clever things. Here are a couple of ideas for you to
try:
|
|
 |
|
Use loops to produce some repeated patterns of your own. |
|