count

 

count is a primitive that reports the number of agents in a given agentset. For example, count turtles reports the total number of all the turtles in a model, while count turtles with [color = green] reports the number of green turtles in the model. You can use count with turtles, patches, and links.

We can also use count with turtle breeds and link breeds such as count dogs or in combination with other reporter agents primitives such as count turtles-here.

In the model example below, we have a dog park at the center and we have a bunch of turtles that represent the dogs in a neighborhood. Our dogs move around completely randomly. When there are more than 5 dogs in the playground at any given time, our model shows a "Playground is too crowded" message.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

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

 
Published NetLogo models that use the count primitive:
 
 
Similar primitives:
mean

Reports the average of a provided list of numerical values.

Read more
mod

Performs the modulo operation; reports the remainder from the division of the first number by the second number.

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
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
 
Learn another primitive: