or

 

or is a logic primitive that takes two conditional statements and reports true if either is true. In other words, it will report true if 1) the first condition is true but the second is false, 2) the second condition is true but the first is false, or 3) both conditions are true. or will report false only if both of the conditions are false. For example, if we wanted to create a model of a predator-prey ecosystem where deer only move if there was no grass nearby or if there was a wolf nearby, we would write the following code:

ask deer [
    if grass-here = 0 or any? wolves in-radius 2 [
        move
    ]
]

Things to keep in mind when using or:

In the model example below, we have some plants and some sheep. Sheep move around randomly and they eat a plant if it is either green or yellow. A magenta plant indicates a poisonous one, so sheep don't eat.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the or primitive:
 
 
Similar primitives:
if

Carries out a provided set of rules (code) if a given condition is true. Does nothing if a given condition is false.

Read more
ifelse

Carries out one set of rules if a given condition is true, and another set of rules if a given condition is false.

Read more
and

Checks if both provided conditions are true.

Read more
of

Reports the value of an agent-owned variable.

Read more
 
Learn another primitive: