Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 18 / 68

Logical operators (AndAlso, OrElse, Not)

This lesson covers VB.NET's logical operators, with the aim of combining several conditions in a judgement.

AndAlso means "both are true", OrElse means "either is true", and Not flips a boolean. Use them when several conditions have to become one judgement.

The sample code checks "18 or over and holding a ticket" with age >= 18 AndAlso hasTicket, and "under 18, or not holding a ticket" with age < 18 OrElse Not hasTicket.

A common early stumble is the difference between And/Or and AndAlso/OrElse. The latter pair short-circuits — skipping the right-hand side when the left already decides the result — which is why they are the default choice.

In professional work, logical operators come up constantly for input checking and permission tests. When a condition gets complicated, grouping the meaningful parts in parentheses keeps it readable.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)