Click (here) to see the discussion about this primitive.
|Summary||Evaluates the boolean value. If it is true, the commands are executed.|
if boolean-value [ commands ]
IF is used to selectively execute commands depending on the outcome of a “test”. The test is a boolean expression–an expression that evaluates to either true or false. *IFELSE* is used to selectively execute some commands if the test is true, or a different set of commands if the test is false.
;; if the current patch is red, move forward 1 unit and turn left and jump again if pcolor = red [ jump 1 lt 90 jump 1] ;; if heading is less than 90 OR greater than 270, set the heading to zero and jump forward ;; otherwise, set the heading to 180 degrees and jump backward ifelse heading > 270 OR heading < 90 [ set heading 0 jump 1 ] [ set heading 180 jump -1 ]