LOGICAL

 !Program name: LOGICAL

!Value of Ln 2

  Logical done/.false./, even/.true./  ! first done and subsequent done values are false until either condition is met at the end of the code.

  I=0

  X=0

1 If (done) then  ! first done and subsequent done values are false and the code goes to else

    Print *, 'Iteration is over. Ln 2 is: ', X

    stop

  else

    I=I+1

    XOLD=X    !first X is zero (even number)

    even= .not. even     ! swap even and not even at each iteration

    If (even) X=X-(1./float(I)) ! the second, fourth, sixth,... X values are computed here.

    If (.not. even) X=X+(1./float(I)) !the first, third, fifth,... X values are computed here.

    Print *, 'XOLD:', XOLD, 'I:', I, 'X:', X

    done=(abs(X-XOLD) .lt. 0.01) .or. (I .ge. 100)

    go to 1

  end if

  end

Comentários

Postagens mais visitadas deste blog

DATA

RECURSIVE

HYDROGEN-RADIAL