previous | start | next

## Nested Loops

- Here is the pseudocode:

  >     print table header
  >     double rate;
  >     for (rate = RATE_MIN; rate <= RATE_MAX;
  >          rate = rate + RATE_INCR)
  >     {
  >        print table row
  >     }

- How do we print a table row? You need to program another loop.

  >     int year;
  >     for (year = YEAR_MIN; year <= YEAR_MAX;
  >          year = year + YEAR_INCR)
  >     {
  >        balance = future_value(initial_balance, rate, year);
  >        cout << setw(10) << balance;
  >     }

- It's a good idea to print the table header as a loop as well.

  >     cout << "Rate     ";
  >     int year;
  >     for (year = YEAR_MIN; year <= YEAR_MAX;
  >          year = year + YEAR_INCR)
  >     {
  >        cout << setw(2) << year << " years";
  >     }

- Once everything is put together, you have the loop printing a single row nested in the loop that traverses the interest rates.

previous | start | next