repeat

 

repeat allows us to execute any set of commands n amount of times back-to-back. repeat is especially useful when drawing geometric shapes in conjunction with the pen-down and pen-up primitives. For example, if we wanted our turtles to draw a square, we would write the following code:

ask turtles [
    pen-down
    repeat 4 [
        right 90
        forward 5
    ]
    pen-up
]

In the model example below, we have 36 turtles who are initially placed in a circle layout when the setup button is clicked. When we click the go button, each turtle turns right 1 degree and moves forward 0.03 units 360 times. This simple repetition behavior results in a very interesting shape.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the repeat primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the repeat primitive:
 
 
Similar primitives:
ask

Asks agents to do things.

Read more
to

Begins a command procedure

Read more
end

Concludes a procedure.

Read more
while

Begins a loop that runs as long as the reporter returns true.

Read more
 
Learn another primitive: