4.4. if...else Double-Selection Statement

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

if ( grade >= 60 )
   cout << "Passed";
else
   cout << "Failed";

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.

Image

Fig. 4.4. if...else double-selection statement activity diagram.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.28.94