program iterate
   implicit none
   ! we would like to solve the nonlinear algebraic equation
   ! x=2-x^3, we already know one solution x=1
   INTEGER, PARAMETER :: SP = KIND(1.0)
   INTEGER, PARAMETER :: DP = KIND(1.0D0)
   integer::i
   real(dp)::x,xnew,eps,diff
   eps=0.1d-2
   diff=1.0d0
   x=1.9        ! to begin with
   i=0;
   do while (diff > eps .and. i<20)
      xnew=2.0d0-x*x*x
      i=i+1
      diff=dabs(xnew-x)
      print*,i,diff,xnew
      x=xnew
   enddo
end program
