Writing Decision Statements

Visual Basic .NET supports only two decision statements: If and Select Case. Here’s the general format of an If statement:

If [condition] Then
'   Statements to execute if condition is true
Else
'   Statements to execute if condition is false
End If

The Else and its following statements are optional. The End If terminator and the line ending after Then are required.

Visual Basic .NET doesn’t care where the keywords If, Else, and End If begin on their respective lines, nor where any statements subordinate to the If and Else begin. It’s customary, however, to left-align the If, Else, and End If keywords uniformly, and to indent any subordinate statements further to the right. This makes complex If statements much easier to read. ...

Get Faster Smarter Beginning Programming 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.