&& Operator

Language Items List

Definition:

Performs a logical conjunction on two expressions.

Syntax:

result = expr1 &&expr2


Syntax Description


expr1, expr2 Any numeric expressions.

Details:

This operator is the boolean, or logical, equivalent of the AND operator. The Truth table is the same as that for the AND Operator, as shown:


expr1 expr2 result


0 0 0

  1. 0 0

0 1 0

  1. 1 1

The difference between the operators is in how the expression is determined as True or False. For &&, the second operand is only evaluated if the first part is True. This means that if the first part is False, the second part is not evaluated; the result is known to be False. For example:

If form1.Font && form1.Font.Size = 10 Then Print size = 10

If this example had been written as shown below, in the case where form1.Font = Nothing, the evaluation of form1.Font.Size would cause:a Not Found exception to be thrown when using the Bitwise AND:

If form1.Font AND form1.Font.Size = 10 Then Print size = 10

It is valid to combine a typeof obj is objname with other expressions, as in: If TypeOf objRef Is Form && a = 1 Then Print true. The logical operators && and || give better results in cases such as this and are recommended over the bitwise operators in similar situations.

See Also:

AND Operator