Web Turtle - "REPEAT" Example

Repeating the Commands In Your Program Instead of Repeating Lines of Code:

If you want to draw a square, you can simply draw a line and turn 90 degrees four times:

DRAW 50
RIGHT 90
DRAW 50
RIGHT 90
DRAW 50
RIGHT 90
DRAW 50
RIGHT 90
(Draw it)

Using the "REPEAT...NEXT" structure, you can do it more easily like this:

REPEAT 4
  DRAW 50
  RIGHT 90
NEXT
(Draw it)

If you want to change how big the square is, you only need to change the number "50" in one place (instead of four places!) Imagine if you had 20-sided shapes! Using loops helps keep your programs from getting huge!

REPEAT 20
  DRAW 50
  RIGHT 18
NEXT
(Draw it)

Looping Loops

Say you want to draw ten squares. Instead of entering some of the code above ten times, you can just put it in a loop:

REPEAT 10
  REPEAT 4
    DRAW 50
    RIGHT 90
  NEXT
  RIGHT 36
NEXT
(Draw it)


"Web Turtle," created by Bill Kendrick, 1997-2017.