Performs short-circuiting logical conjunction on two expressions.
result = expression1 AndAlso expression2
If both expression1 and expression2 evaluate to True, result is True. If expression1 evaluates to True and expression2 evaluates to False, result is False. If expression1 evaluates to False, expression2 is not evaluated, and result is False (the operator is said to have short-circuited the expression). The following table illustrates how result is determined:
If expression1 is | And expression2 is | Value of result is |
---|---|---|
True | True | True |
True | False | False |
False | (not evaluated) | False |
This example uses the AndAlso operator to perform a logical conjunction on two expressions. The result is a Boolean value that represents whether the entire conjoined expression is true. If the first expression is False, 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 > BAndAlso
B > C ' True. myCheck = B > AAndAlso
B > C ' False. Second expression not evaluated. myCheck = A > B AndAlso C > B ' False. Second expression evaluated. ' This example demonstrates using the AndAlso operator to search through ' array values. If i is greater than the upper bound of the array, it does ' attempt to find a corresponding value in the array. Dim i As Integer = 0 While i <= UBound(arr)AndAlso
arr(i) <> SearchValue i += 1 End While
Logical/Bitwise Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality |