5.3. If...Then Selection Statement

A selection statement chooses among alternative courses of action. For example, suppose that the passing grade on an examination is 60 (out of 100). Then the statement

					If studentGrade >= 60
					Then
   Console.WriteLine ("Passed")
End If
				

outputs the string "Passed" if the student’s grade is at least 60.

The preceding If...Then selection statement also could be written on a single line as

					If studentGrade >= 60
					Then Console.WriteLine("Passed"
				

In the multiple-line format, all statements (there can be many) in the body of the If...Then are executed if the condition is true. In the single-line format, only the statement immediately after the Then keyword is executed if the condition is true. Although writing the If ...

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.