### Logical Expressions

Logical expressions (also called Boolean expressions) are the result of applying logical (Boolean) operators to relational or arithmetic expressions. The result of an operation has two possible states: true or false. Logical expressions are considered false when equal to 0, and are considered true when nonzero.

Logical operators have the lowest precedence and are evaluated after all other operations have been evaluated. If two or more logical operators appear in an expression, the leftmost operator is performed first.

Logical operators act on their associated operands as illustrated below:

 a or b is true (evaluates to 1) if a is true or b is true. a ! b is false (evaluates to 0) if a and b are both false. a and b is true (evaluates to 1) only if both a and b are true. a & b is false (evaluates to 0) if a is false or b is false or both are false.

The not() function negates the effect of a logical expression:

 not(a or b) is true (evaluates to 1) if a is false or b is false. not(a and b) is true (evaluates to 1) if a and b are false.

Example(s)

The then clause is taken when x is a nonzero numeric. Whether x is a numeric constant, or an ASCII string, any nonzero numeric value of x is true.

 if x then...

This prints An apple, because chr = "a".

 word = "apple" chr = word[1,1] print "A": print str("n",chr="a" or chr = "e" or chr = "i" or chr = "o" or chr = "u") : print " ":word

In this example, the then clause is executed if visit.date evaluates to a nonzero numeric.

 visit.date = customer.item<5> if visit.date then...

The then clause is taken if x is between 1 and 10, exclusive.

 if x > 1 and x < 10 then...

The then clause is taken if x is between either 1 and 10, exclusive, or between 100 and 200, inclusive.

 if (x > 1 and x < 10) or (x >= 100 and x <= 200) then...

The printer on statement is executed if the value of print.flag is not n.

 if not(print.flag = "n") then printer on