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

If - Then

Learn how to use If - Then statements

The If-Then statement is used to execute commands given that a set of conditions are satisfied. The basic structure of an If-Then statement is like the one below.

If x < 4 then
 x = x + 1
End If

OR

If [condition] then 
 [command lines]
End If

You can also put additional commands if a condition does NOT hold. You can use the "Else" command to do this. An example of how this is used is shown below.

If x < 4 then
 z = x + 3
Else
 z = x + 9
End If

OR

If [condition] then
 [command lines]
Else
 [command lines]
End If