Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

OrElse Operator

Used to perform short-circuiting logical disjunction on two expressions.

result = expression1 OrElse expression2

Parts

result
Required. Any Boolean expression.
expression1
Required. Any Boolean expression.
expression2
Required. Any Boolean expression.

Remarks

A logical operation is said to be short-circuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the other expression, because it cannot change the final result. Short-circuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls.

If either expression1 or expression2 evaluates to True, result is True. If expression1 evaluates to True, expression2 is not evaluated, and result is True (the operator is said to have short-circuited the expression). The following table illustrates how result is determined:

If expression1 is And expression2 is Then result is
True (not evaluated) True
False True True
False False False

Example

This example uses the OrElse operator to perform logical disjunction on two expressions. The result is a Boolean value that represents whether either of the two expressions is true. If the first expression is True, the second is not evaluated.

Dim A As Integer = 10
Dim B As Integer = 8
Dim C As Integer = 6
Dim myCheck As Boolean
myCheck = A > B OrElse B > C   ' True. Second expression is not evaluated.
myCheck = B > A OrElse B > C   ' True. Second expression is evaluated.
myCheck = B > A OrElse C > B   ' False.

If MyFunction(5) = True OrElse MyOtherFunction(4) = True Then 
' If MyFunction(5) is True, MyOtherFunction(4) is not called.
   ' Insert code to be executed.
End If

See Also

Logical/Bitwise Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | Or Operator | Logical Operators

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft