Indenting Nested if Statements

Although the compiler doesn't care about formatting, you as the programmer do. The previous example without any indentation is much harder to follow and to understand the flow of logic:

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';

Next page
Previous page
Go to Lesson 7 index.


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