Boolean AND 'AND', 'AND='

The Boolean AND 'AND' operator compares two operands and returns TRUE (-1) if both values are TRUE (non-zero), or returns FALSE (0) if one or both operands are FALSE (0). Boolean AND can be used in both variable and constant expressions.

Example:

X := Y AND Z

The above example compares the value of Y with the value of Z and sets X to either: TRUE (-1) if both Y and Z are non-zero, or FALSE (0) if either Y or Z is 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 and Z is true…"

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

IF (Y == 20) AND (Z == 100)

This example evaluates the result of Y == 20 against that of Z == 100, and if both are true, the Boolean AND operator returns TRUE (-1).

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

X AND= True     'Short form of X := X AND True

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

Be careful not to get Boolean AND 'AND' confused with Bitwise AND '&'. Boolean AND is for comparison purposes while Bitwise AND is for bit manipulation (see    ).

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