Boolean OR 'OR', 'OR='

The Boolean OR 'OR' operator compares two operands and returns TRUE (-1) if either value is TRUE (non-zero), or returns FALSE (0) if both operands are FALSE (0). Boolean OR can be used in both variable and constant expressions. Example:

X := Y OR Z

The above example compares the value of Y with the value of Z and sets X to either: TRUE (-1) if either Y or Z is non-zero, or FALSE (0) if both Y and Z are zero. During the comparison, it promotes each of the two values to -1 if they are non-zero, making any value, other than 0, a -1, so that the comparison becomes: "If Y is true or Z is true…"

Quite often this operator is used in combination with other comparison operators, such as in the following example.

IF (Y == 1) OR (Z > 50)

This example evaluates the result of Y == 1 against that of Z > 50, and if either are true, the Boolean OR operator returns TRUE (-1).

Boolean OR has an assignment form, OR=, that uses the variable to its left as both the first operand and the result destination. For example,

X OR= Y     'Short form of X := X OR Y

Here, the value of X is promoted to TRUE if it is non-zero, then is compared with Y (also promoted to TRUE if non-zero) and the Boolean result (TRUE / FALSE, -1 / 0) is stored back in X. The assignment form of Boolean OR may also be used within expressions for intermediate results; see Intermediate Assignments.

Be careful not to get Boolean OR 'OR' confused with Bitwise OR'|'. Boolean OR is for comparison purposes while Bitwise OR is for bit manipulation (see '!' - Bitwise NOT).

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.