and

 

and is a primitive that allows us to combine two true-false statements into one single statement that is true if and only if both statements are true.

For example, if we wanted a turtle to eat only if (A) they were hungry and (B) if there was food on the same patch, we could say:

if my-hunger-level > 100 and food-here > 0 [
  eat-food
  set my-hunger-level 0
]

Things to keep in mind when using and:

In the model example below, we use and to generate a river down the middle of our world. A patch turns blue if and only if its x-coordinate is both to the left of (width / 2) and to the right of - (width / 2), otherwise, it remains a green patch.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the and 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
or

Checks if either of two provided conditions is true.

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
with

Reports a subset of the original agentset that only contains the agents with specified characteristics.

Read more
 
Learn another primitive: