Difference between revisions of "Boolean Expressions"

From SCI Wiki
Jump to navigationJump to search
 
(3 intermediate revisions by the same user not shown)
Line 16: Line 16:
  
 
= x 1
 
= x 1
(if(x) // evaluates to true
+
(if(x)   // evaluates to true
 
     Print("True: x is non-zero") // this will be output
 
     Print("True: x is non-zero") // this will be output
 
)(else
 
)(else
Line 23: Line 23:
  
 
= x 9387
 
= x 9387
(if(x) // also evaluates to true
+
(if(x)   // also evaluates to true
 
     Print("True: x is non-zero") // this will be output
 
     Print("True: x is non-zero") // this will be output
 
)(else
 
)(else
Line 34: Line 34:
 
[[Category:Examples]]
 
[[Category:Examples]]
 
[[Category:Syntax]]
 
[[Category:Syntax]]
 +
[[Category:Conditionals]]

Latest revision as of 20:11, 2 December 2015

Originally posted on the SCI Programming forum by Gumby

Boolean (true/false) expressions are handled as one might expect, with one subtlety. A value of 'true' is actually the result any expression evaluating to a non-zero value. I believe this is handled the same as most programming languages, but thought it was worth noting anyway.

To illustrate:

Code:
(var x)

= x 0
(if(x)    // evaluates to false
    Print("True: x is non-zero")
)(else
    Print("False: x is zero")   // this will be output
) 

= x 1
(if(x)    // evaluates to true
    Print("True: x is non-zero") // this will be output
)(else
    Print("False: x is zero")
) 

= x 9387
(if(x)    // also evaluates to true
    Print("True: x is non-zero") // this will be output
)(else
    Print("False: x is zero")
)