Nested if else Statements

Nested if…else Statements:
Nested if…else statements test for multiple cases by placing if…else statements inside
if…else statements. For example, the following pseudocode statement will print A for
exam grades greater than or equal to 90, B for grades greater than or equal to 80 (but less
than 90), C for grades greater than or equal to 70 (but less than 80), D for grades greater
than or equal to 60 (but less than 70), and F for all other grades

If the variable grade is greater than or equal to 90, all four conditions will be true, but only
the puts statement after the first test will be executed. After that puts is executed, the else
part of the “outer” if…else statement is skipped.
You may prefer to write the preceding if statement as

  if ( grade >= 90 ) {
puts( “A” );
} // end if
else if ( grade >= 80 ) {
puts( “B” );
} // end else if
else if ( grade >= 70 ) {
puts( “C” );
} // end else if
else if ( grade >= 60 ) {
puts( “D” );
} // end else if
else {
puts( “F” );
} // end else

ANOTHER EXAMPLE IS:

if (balance > 50000.00) 

interestRate = 0.07; 

else
if (balance >= 25000.00) 
interestRate = 0.05; 

else 
if (balance >= 1000.00)
interestRate = 0.03;

else 
interestRate = 0.00;