The Extended if Statement

Used to prevent the cascading indentation present in the previous example. Uses an else if structure. It is not really a new form of the if . . . else statement, but rather a way of formatting the output for easy readability. The compiler sees no difference.

The meaning of this if . . . else statement is identical to the two previous examples:

if (average >= 90)
  grade = 'A';
else if (average >= 80)
  grade = 'B';
else if (average >= 70)
  grade = 'C';
else if (average >= 60)
  grade = 'D';
else
  grade = 'F';

Notice that the indentation is at the same level, no matter how many conditional expressions you have.

Next page
Previous page
Go to Lesson 7 index.


HTML by Jennifer Keiser.
Sponsored by Inspiration, the diagramming and outlining tool.