And Then Operator

Performs a logical conjunction with short-circuit evaluation.

Syntax

expression_1 And Then expression_2

Parts

expression_1
Necessary Boolean expression
expression_2
Necessary Boolean expression

Instructions

The result is of type Boolean.

The And Then operator closely resembles the And operator, except when the first operand evaluates as false. When this occurs, the second operand is not evaluated at all. This is valid behavior because the falseness of the operation can always be proven whenever the first operand is false. This is known as short-circuit evaluation. The following truth table summarizes this behavior.

If expression_1 isAnd expression_2 isThe result is
TrueTrueTrue
TrueFalseFalse
Falsenot evaluatedFalse

Examples

Example 1

In this example, “parts” was provided by the user.

If parts > 0 And Then whole / parts >= minimun Then
    ' do something
End If

Example 2

If #h Is Object And Then #h.SomeMethod? Then
    ' do something
End If

See also