Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

4.6 If...Then...Else Selection Statement

The If...Then...Else selection statement allows you to specify that a different action (or sequence of actions) is to be performed when the condition is true than when the condition is false. For example, the pseudocode statement

   If student's grade is greater than or equal to 60 then
    
   Display "Passed"

   Else
    
   Display "Failed"

displays "Passed" if the student's grade is greater than or equal to 60, and displays "Failed" if the student's grade is less than 60. In either case, after the display occurs, the next pseudocode statement in sequence is "performed."

The preceding pseudocode If...Else statement may be written in Visual Basic as


If studentGrade >= 60 Then
   resultLabel.Text = "Passed" ' display "Passed"
Else
   resultLabel.Text = "Failed" ' display "Failed"
End If

               

The body of the Else clause is indented so that it lines up with the body of the If clause.

UML Activity Diagram for the If...Then...Else Selection Statement

Figure 4.3 illustrates the flow of control in the If...Then...Else statement.

Figure 4.3

Fig. 4.3 If ... Then ... Else double-selection statement activity diagram.

  • + Share This
  • 🔖 Save To Your Account