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:
Calculating Interest Example |