Skip to main content

4.5) Working With Variables (=, SET)


For working with variables two fundamentally different sets of operations are important. (i) “assignment” operation which updates the value of a variable, and (ii) “conditional” operations, which check if a value of the variable satisfies some condition. For assignment statements the primitive set is used and not =, and for conditional statements boolean operators (<, >, =, !=, <=, >=)are used.

Assignment Statements

Wrong:

happiness = ([happiness] of a-neighbour-turtle)

Right:

set happiness ([happiness] of a-neighbour-turtle)


Conditional statements

Boolean (Yes Or No)

if happiness = 3 [stop]
if happiness > 17 [stop]
if happiness != 5 or ticks > 17 [stop]