Logical Operators

Logical operators take Boolean (logical) values as operands and return a Boolean value.

Table 30. Logical Operators

Operator

Description

AND (&&)

Connects two conditional expressions and retrieves records only if each expression is true.

Computed items are not retrieved if any condition belonging to a conditional expression is false. The AND logical operator is usually nested within another conditional expression, for example, expressions which use if and else statements. For example:

if ((OS == ‘Windows’) && (Item type == ‘Modem’)) {‘Windows’} else {‘other’}

OR (||)

Specifies a combination of expressions and retrieves records that include at least one of the expressions. For example, if one of the words is Washington or Oregon, every record with the expression “Washington” and every record with the word “Oregon” is included.

Typically the OR (||) is nested within other conditional expressions, for example, expressions which use if and else logical operators. For example if you want to assign Washington and Oregon to the "Northwestern Region" and all other states to "Other Regions", enter:

if ((State = = ‘Washington’)|| (State == ‘Oregon’)) {‘Northwestern Region’} else {‘Other Regions’}

NOT (!)

Computes and shows items more accurately stated in a negative way. In effect, all records are retrieved except those that fulfill the conditional expression.

You enter the conditional expression with the NOT (!) logical operator preceding the conditional expression. The conditional expression can be a simple value or nested within other conditional expressions, for example, expressions using AND and OR.

A combined condition expression that uses NOT is true if the conditional expression following NOT is false. A combined conditional expression is false if the conditional expression following NOT is true.

For example, suppose you are looking to list all states that are not in the Northwestern region. In this case, enter the conditional expression:

if ( ! (State = = 'Northwestern Region')) {‘Other Regions’}