OrElse Operator
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

OrElse Operator

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

result = expression1 OrElse expression2


Required. Any Boolean expression.
Required. Any Boolean expression.
Required. Any Boolean expression.


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


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

© 2015 Microsoft