Logic and Control

Wait and Escape

A procedure can halt its own execution using the stop command:

stop

In this example "goodbye" is never printed:

to print-and-stop
�� print "hello"
�� stop
�� print "goodbye"
end

A procedure can pause for a specified number of seconds using the wait command:

wait SECONDS

In this example "goodbye" is printed 10 seconds after "hello" is printed:

to print-and-wait
�� print "hello"
�� wait 10
�� print "goodbye"
end

Sequential Execution

A block is a list of commands that are executed in the order they appear:

[COMMAND1 COMMAND2 COMMAND3 ... ]

Click here for details.

Boolean Logic

NetLogo has the ability to compare strings and numbers (=, !=, <, <=. >, >=) and has the usual collection of Boolean operators (and, or, not, xor) and literals (true, false).

Example:

not felon? and (gpa > 3.0 or 100000 <= donation)

A condition is a Boolean-valued expression.

Conditional Execution

if CONDITION [COMMANDS]

ifelse CONDITION [THEN-COMMANDS] [ELSE-COMMANDS]

ifelse-value CONDITION [THEN-EXPRESSION] [ELSE-EXPRESSION]

Click here for examples.

Iterative Execution

while [CONDITION] [COMMANDS]

repeat NUMBER [COMMANDS]

loop [COMMANDS]

every SECONDS [COMMANDS]

foreach LIST [COMMANDS]

ask AGENTS [COMMANDS]

ask-concurrent AGENTS [COMMANDS]

Click here for examples.