any?

 

any? is used to determine if there are at least one agent within a given agentset. If there are, it will return true, otherwise it will return false.

For example, the following code would repeat running the go procedure on a repeated basis as long as there is at least 1 turtle in the model. If, let's say, there were many turtles but they could die, the model would stop when all the turtles die.

to go
    if not any? turtles [
        stop
    ]
    tick
end

We can combine any? with a conditional reporter using the with primitive such as the following example that stops the model if any of the turtles in the model are smaller than 1 unit:

if any? turtles with [size < 1] [stop]

Things to keep in mind in mind when using any?:

The model example below represents the spread of a contagious disease within a healthy population. We use any? primitive to run the model as long as there is at least one healthy (green) individual in the model. Once all of the individuals turn red, the model automatically stops.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the any? primitive:
 
 
Similar primitives:
all?

Checks if a reporter is true for all the agents in an agentset.

Read more
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
other

Reports an agentset which is the same as the input agentset but omits the agent that used this primitive.

Read more
nobody

A special value that helps checking if an agent exists or not.

Read more
 
Learn another primitive: