If...Then...Else Operator

Evaluates one of two expressions based on a condition.

Syntax

If condition Then expression1 Else expression2

Parts

condition
Required Boolean expression
expression1
Required expression
expression2
Required expression

Remarks

The If...Then...Else operator closely resembles the If...Then...Else statement, except the operator evaluates expressions rather than statements.

When condition evaluates to true, expression1 is evaluated and its value is the result of the operation—expression2 is not evaluated. When condition evaluates to false, expression2 is evaluated and its value is the result of the operation—expression1 is not evaluated.

Normally, expression1 and expression2 must be compatible types. One exception is when the enclosing expression can accept more than one data type, such as a polymorphic method.

Examples

See also