- Introduction
- Control Structures
- If/Then Selection Structure
- If/Then/Else Selection Structure
- While Repetition Structure
- DoWhile/Loop Repetition Structure
- DoUntil/Loop Repetition Structure
- Do/LoopWhile Repetition Structure
- Do/LoopUntil Repetition Structure
- Assignment Operators
- For/Next Repetition Structure
- Example: Using the For/Next Structure to Compute Compound Interest
- SelectCase Multiple-Selection Structure
- Using the Exit Keyword in a Repetition Structure
- Logical Operators
- Introduction to Windows Application Programming
- Summary
3.3 If/Then Selection Structure
In a program, a selection structure chooses among alternative courses of action. For example, suppose that the passing grade on an examination is 60 (out of 100). Then the Visual Basic .NET code
If studentGrade >= 60 Then Console.WriteLine("Passed") End If
determines whether the condition studentGrade>=60 is true or false. If the condition is true, then "Passed" is printed, and the next statement in order is "performed." If the condition is false, the Console.WriteLine statement is ignored, and the next statement in order is performed. A decision can be made on any expression that evaluates to a value of Visual Basic's Boolean type (i.e., any expression that evaluates to True or False).