Boolean Operators

All Boolean operators return 1 (‘nonzero’), if the condition is met (i.e., True) and 0 if the condition is not met (i.e., False).

The operator ‘not’ can be used to negate an expression, but remember to use parenthesis, since ‘not’ is stronger (i.e., of higher precedence) than all other operators.

For example: 

The expression:     ‘not 1 > -1’
Is evaluated as:     ‘(not 1) > -1’, which equals: ‘0 > -1’;
Yields a result of:   1 (i.e., non-zero which represents a logical value of ‘True’)

Whereas, using parenthesis to properly group when using the ‘not’ operation as recommended:      ‘not(1 > -1)’
Is evaluated as:     ‘not(1)’,
Yields result of:     0 (i.e., zero which represents a logical value of ‘False’).

 

 

The other Boolean operators are all weaker (i.e., of lower precedence) than the arithmetic operators.

 

Boolean Operator

Boolean Operator Description

Not Operator:

not

Nonzero (i.e., True), if the expression after ‘not’ is zero, otherwise zero.

Note: The ‘not’ operator has the highest precedence (i.e., the strongest) and may require the use of parenthesis to ensure that it is evaluated as expected.

Relational Boolean Operators:

=, <, <=, >, >=, <>

The Value comparison operators:

§ Equal (=)

§ Less Than (<)

§ Less Than or Equal (<=)

§ Greater Than (>)

§ Greater Than or Equal (>=)

§ Not Equal (<>)

Logical And Operator:

and

Evaluates to Nonzero (i.e., True), if the expressions on either side of the ‘and’ operator are both nonzero.

Logical Or Operator: or

Evaluates to Nonzero (i.e., True), if one or both of the expressions on either side of ‘or’ is nonzero.