Logical Operators
  • 30 Jan 2024
  • PDF

Logical Operators

  • PDF

Article summary

And Operator

Used to perform a logical conjunction on two expressions.

Syntax: result = expr1 And expr2

Remarks: If, and only if, both expressions evaluate True, result is True.  If either expression evaluates False, result is False.  The following table illustrates how result is determined:

If expr1 is

And expr2 is

The result is

True

True

True

True

False

False

True

Null

Null

False

True

False

False

False

False

False

Null

False

Null

True

Null

Null

False

False

Null

Null

Null

  Example: This example displays a message that depends on the value of variables A, B, and C, assuming that no variable is a Null.  If A = 10, B = 8, and C = 6, both expressions evaluate True.  Because both expressions are True, the And expression is also True.

A = GD(1)

B = GD(2)

C = GD(3)

If A > B And B > C Then 

Result = A

Else

Result = 0

End If

Not Operator

Used to perform logical negation on an expression.

Syntax: result = Not expr

Remarks: The following table illustrates how result is determined:

If expr is

Then result is

True

False

False

True

Null

Null

 If an integer variable has the value 0 ( False), the variable becomes -1 ( True); if it has the value -1, it becomes 0. 

Example: This example checks the opposite of the logical comparison of A and B, assuming neither variable is a Null.  If A = 10 and B = 8, the Not expression evaluates True because A is not equal to B.

A = GD(1)

B = GD(2)

If Not A = B Then              

Result = A

Else

Result = 0

End If

Or Operator

Used to perform a logical disjunction on two expressions.

Syntax: result = expr1 Or expr2

Remarks: If either or both expressions evaluate True, result is True.  The following table illustrates how result is determined:

If expr1 is

And expr2 is

The result is

True

True

True

True

False

True

True

Null

True

False

True

True

False

False

False

False

Null

Null

Null

True

True

Null

False

Null

Null

Null

Null

 Example: This example displays a message that depends on the value of variables A, B, and C, assuming that no variable is a Null.  If A = 10, B = 8, and C = 11,  the left expression is True and the right expression is False.  Because at least one comparison expression is True, the Or expression evaluates True.

A = GD(1)

B = GD(2)

C = GD(3)

If A > B Or B > C Then

Result = A

Else

Result = 0

End If


Was this article helpful?