Knitting a scarf: another example of nested For loopsTopCounting and For loopsCalculating Interest Example

Calculating Interest Example

Let's see another example of a for loop. Suppose that we wanted to determine how much money we would have if we invested it for 10 years, gaining 5% interest each year (compounded annually). Suppose amount represents the amount of money we have invested. After one year, we would have:

    amount + amount * 5/100.0;

Below is a demo that uses a for loop to repeat this computation 10 times:

Demo: Interest rates
Knitting a scarf: another example of nested For loopsTopCounting and For loopsCalculating Interest Example