! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 4.17. Compute factorials of all nonnegative integers.
  program E17
    implicit none
    integer :: Limit, Factorial, Loop
! start program E17
    Limit = 0
Outer_Loop: do
      Factorial = 1
      do Loop = 1, Limit
        if (Factorial > huge( 1 ) / Loop) then
          write (unit = *, fmt = *) " The factorial of ", Limit, " is a very large integer. "
          exit Outer_Loop
        else
          Factorial = Factorial * Loop
        end if
      end do
      write (unit = *, fmt = *) " The factorial of ", Limit, " is: ", Factorial
      Limit = Limit + 1
    end do Outer_Loop
    stop
  end program E17
