6.10. Logical Operators

So far, we have studied only simple conditions, such as count <= 10, total > 1000 and number <> sentinelValue. Each selection and repetition statement evaluated only one condition with one of the operators >, <, >=, <=, = and <>. To make a decision that relied on the evaluation of multiple conditions, we performed these tests in separate statements or in nested If...Then or If...Then...Else statements.

To handle multiple conditions more efficiently, Visual Basic provides logical operators that can be used to form complex conditions by combining simple ones. The logical operators are And, Or, AndAlso, OrElse, Xor and Not. We consider examples that use each of these operators.

Logical And Operator

Suppose we wish to ensure ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.