Learning goals
- Repeat commands with a
forloop.- Choose how many times to repeat with
range().- Draw a square, a triangle and a rectangle with the right turns.
This program repeats two commands four times to draw a square.
import turtle as otto
for side in range(4):
otto.forward(60)
otto.left(90)

The indented commands repeat four times. Each time, the turtle draws one side and turns.
| Code or idea | What it does |
|---|---|
for loop |
Repeats a group of commands. |
range(4) |
Gives four numbers, from 0 to 3. The loop repeats four times. |
Loop variable (side) |
Holds the current number. A variable is a name for a value. |
| Indentation | Shows which commands belong to the loop. |
| Square | Four equal sides. Turn 90 degrees after each side. |
| Triangle | Three equal sides. Turn 120 degrees after each side. |
| Rectangle | Long and short sides take turns. Turn 90 degrees after each side. |