Logical Operators

Logical operators were used in the Using Sets section when we introduced set looping functions. In LINGO, logical operators are primarily used in conditional expressions on set looping functions to control which members of a set are to be included or excluded in the function. They also play a role in building set membership conditions.

Logical operators return either TRUE or FALSE as a result. LINGO uses the value 1 to represent TRUE, and the value 0 to represent FALSE. LINGO considers an argument to be FALSE if, and only if, it is equal to 0. Thus, for example, arguments of 1, 7, -1, and .1234 would all be considered TRUE.

LINGO has nine logical operators, which are all binary with the single exception of the #NOT# operator, which is unary. LINGO's logical operators and their return values are listed below:

Logical Operator

Return Value

#NOT#

TRUE if the operand immediately to the right is FALSE, else FALSE.

#EQ#

TRUE if both operands are equal, else FALSE.

#NE#

TRUE if both operands are not equal, else FALSE.

#GT#

TRUE if the left operand is strictly greater than the right operand, else FALSE.

#GE#

TRUE if the left operand is greater-than-or-equal-to the right operand, else FALSE.

#LT#

TRUE if the left operand is strictly less than the right operand, else FALSE.

#LE#

TRUE if the left operand is less-than-or-equal-to the right operand, else FALSE.

#AND#

TRUE only if both arguments are TRUE, else FALSE.

#OR#

FALSE only if both its arguments are FALSE, else TRUE.

The priority ranking of the logical operators is:

Priority

Level

Operator(s)

Highest

#NOT#

 

#EQ#   #NE#   #GT#   #GE#   #LT#   #LE#

Lowest

#AND#   #OR#