This documentation is archived and is not being maintained.

AndAlso Operator

Performs short-circuiting logical conjunction on two expressions.

result = expression1 AndAlso expression2


Required. Any Boolean expression. The result is the Boolean result of comparison of the two expressions.
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 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 > B AndAlso B > C   ' True.
myCheck = B > A AndAlso B > C   ' False. Second expression not evaluated.
myCheck = A > B AndAlso C > B   ' False. Second expression evaluated.

Public Function FindValue(ByVal Arr() As Double, _
                          ByVal SearchValue As Double) As Double
   Dim I As Integer = 0
   While I <= UBound(Arr) AndAlso Arr(I) <> SearchValue
   ' If I is greater than UBound(Arr), SearchValue is not checked.
      I += 1
   End While
   If I >= UBound(Arr) Then I = –1
   Return I
End Function

See Also

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