If Else

From StarLogo Nova Wiki
Other languages:
The If Else Block

Test for something. If true, then the agent follows the commands in the first hook. If false, then the agent follows the commands in the “else” hook.

Syntax

Inputs in this block:

  1. a comparative statement block (= statements, > statements, not statement, and/or statements)

Example

If Else example gif
If Else example code

This is a model of a hungry frog attempting to catch two different types of fly. While ‘fly around’ is toggled, the frog moves toward the closest fly. The fly detects whether the frog is nearby and will move in the opposite direction. The if else block is used to determine the speed of each fly based on the size of each agent. In this case, large flies are fast, whereas small flies are slow. It can be seen from the line graph that the population of the larger, faster flies falls more slowly than the smaller, slower flies.