Q:

how to get a value when looping in FORTRAN

Hello guys! There is a population of say, 120 million, which increases by 8% every year. I want to have a DO loop starting from 1990 to 2020 to state the year the population exceeds 125 million. Pseudocode or Fortran code will be appreciated.

A:

This is not a problem for which loops are either necessary or appropriate.  The simple equation
num_years = log(125.0/120.0)/log(1.08)

(which evaluates to approximately 0.53) is all that is necessary. This is a straightforward rewriting of the formula for compound interest calculations, that is
compound_amt = initial_amt * (1+interest_rate)**num_years

with, in this case, initial_amt = 120*10**6, compound_amt = 125*10**6 and interest_rate = 8%.

