if

Click (here) to see the discussion about this primitive.

Summary Evaluates the boolean value. If it is true, the commands are executed.
Syntax
if boolean-value [ commands ]
Version –na–
Tags flow-control
Used By universal
CCL Link dictionary==>if

Description

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.

Example:

;; 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
] 

Details

Discussion

 
prim/if.txt · Last modified: 2009/09/09 09:40 by 199.4.155.10
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki