The if
single-selection statement performs an indicated action only when the condition is true; otherwise the action is skipped. The if
...else
double-selection statement allows you to specify an action to perform when the condition is true and a different action to perform when the condition is false. For example, the statement
displays "Passed"
if grade >= 60, but displays "Failed"
if the student’s grade is less than 60. In either case, the next statement in sequence is then performed. The body of the else
is also indented. Figure 4.4 illustrates the the if
...else
statement’s flow of control.