next up previous contents index
Next: A loop with for Up: Loops: Previous: Loops:   Contents   Index


A loop with repeat

This is the syntax for repeat:
repeat n list_of_commands

n is a whole number and list_of_commands is a list containing the commands to execute. The LOGO interpreter will implement the commands in the list n times: that avoids the need to copy the same command n times!
Eg:

repeat 4 [forward 100 left 90]      # A square of side 100
repeat 6 [forward 100 left 60]      # A hexagon of side 100
repeat 360 [forward 2 left 1]       # A uh... 360-gon of side 2
                                           # In short, almost a circle!
Included in a repeat loop. Its an internal variable. Returns the number of the running iteration. (The first iteration is number 1).

repeat 3 [pr repcount]
1
2
3


Loïc 2008-06-08