Home » VB.NET Basics » 06 - Conditional Logic
6

Conditional Operators

Learn to use conditional operators and how to combine them

Conditional Operators

Operators that describe or state a relationship on one side of an expression with the other side of an expression is called a relational or conditional operator. The "=" sign is an operator that states that the values on the left side of the expression is equal to the right side of the expression, thus making it an equation. There are many other conditional operators that you can use in Visual Basic. They are the following.

  • The "<" sign is used to describe an expression where the left side is "less than" the right side.
  • The ">" sign is used to describe an expression where the left side is "greater than" the right side.
  • The "<=" sign is used to describe an expression where the left side is "less than OR equal to" the right side.
  • The ">=" sign is used to describe an expression where the left side is "greater than OR equal to" the right side.
  • The "<>" sign is used to describe an expression where the left side is "not equal to" the right side.

Using the conditional operators is as simple as using a see saw.

Combining Conditional Operators

You can combine the use of conditional operators using the following commands.

The "AND" command combines two conditional operators together. See the code below for an example.

 If x > 5 and y < 3 then z = x - y 

The "OR" command selects which one of the two conditional operators are satisfied or dissatisfied. See the code below for an example.

 If x < 5 or y > 6 then z = x + y