ifelse-value

ifelse-value reporter [reporter1] [reporter2]

Reporter must report a boolean (true or false) value.

If reporter reports true, the result is the value of reporter1.

If reporter reports false, the result is the value of reporter2.

This can be used when a conditional is needed in the context of a reporter, where commands (such as ifelse) are not allowed.

ask patches [
  set pcolor ifelse-value (pxcor > 0) [blue] [red]
]
;; the left half of the world turns red and
;; the right half turns blue
show n-values 10 [ifelse-value (? < 5) [0] [1]]
=> [0 0 0 0 0 1 1 1 1 1]
show reduce [ifelse-value (?1 > ?2) [?1] [?2]]
  [1 3 2 5 3 8 3 2 1]
=> 8

See also if, ifelse.

Take me to the full NetLogo Dictionary