Used to perform short-circuiting logical disjunction on two expressions.
result = expression1 OrElse expression2
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 > BOrElse
B > C ' True. Second expression is not evaluated. myCheck = B > AOrElse
B > C ' True. Second expression is evaluated. myCheck = B > AOrElse
C > B ' False. ' This example demonstrates the use of the OrElse operator. If the first ' function call returns true, the second function call is not made. If MyFunction(5) = True OrElse MyOtherFunction(4) = True Then ' Insert code to be executed. End If
Logical/Bitwise Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality |