10     CONTINUE

C      Input integer
       WRITE(6, 1)
1      FORMAT(1X, 'Enter an integer between 1 and 12 or 0 to exit')

       READ(5,7, ERR=4) J
7      FORMAT(I2)

C      If 0 is entered, jump to end
       IF(J .EQ. 0) GO TO 6

C      Check input
       IF(J .LT. 0) GO TO 4
       IF(J .GT. 12) GO TO 4

C      M = final factorial number, intialized to 1, then multiplied to
C        J!
       M = 1
       DO 2 I = 1, J, 1

       M = M*I
2      CONTINUE

C      Print result
       WRITE(6,3) J, M
3      FORMAT(1X, I2, ' factorial is ', I10)

C      Repeat
       GO TO 10

C      This is only reached on exit
6      CONTINUE
       WRITE(6,11)
11     FORMAT(1X, 'Goodbye!')
       STOP

C      When an error arises, we go here
4      WRITE(6,5)
5      FORMAT(1X, 'Incorrect input, try again')
       GO TO 10

       END
