C      Dimension is the same as array. Declares an array called fib with
C      10 elements. Arrays are 1-based, unlike Java and C. Arrays must
C      be the first thing declared in the file, and must have static
C      sizes. Starting the name with I means that you get an array of
C      ints.
       DIMENSION IARRAY(26)

C      Array indices are accessed through parentheses
C      you generate a serious exception if you try to access a place
C      that does not exist
       IARRAY(1) = 0
       IARRAY(2) = 1
       
C      The write function takes two arguments, the output location, and
C      the label of the format statement to use. 6 is used as STDOUT
   11  WRITE(6,1)
   1   FORMAT('ENTER IN A NUMBER BETWEEN 2 & 26, inclusive (0 '
     6 'to quit) ')
       READ (5,2, ERR=996) ITERS
   2   FORMAT (I4)

C      The if statement is evaluated and if it is true, the statment
C      following it is executed, otherwise, the statement on the next
C      line is executed
C      FORTRAN allows you to jump to a line of code with the given label
       IF (ITERS .EQ. 0) GOTO 9999

       IF (ITERS .LE. 26) GOTO 900
       GO TO 998

900    IF (ITERS .GE. 2) GOTO 3
996    WRITE(6, 997)

997    FORMAT(1X, 'Only integers between 2 & 100 allowed.')
       GOTO 9999

998    WRITE(6, 999)
999    FORMAT(1X, 'Your input was not within the acceptable range '
     6 '[2,100]')
       GO TO 9999

C      Initialize an array index variable.
C      Since the variable starts with I, it is automatically an integer
3      INDEX = 3

C      Since the variable does not start with I-N,
C      it must be declared as an integer
       ITOTAL = IARRAY(1) + IARRAY(2)
       GO TO 100

5      INDEX = INDEX + 1
       IF (INDEX .GT. ITERS) GO TO 1000
       GO TO 100

100    ITOTAL = IARRAY(INDEX-2) + IARRAY(INDEX-1)
       IARRAY(INDEX) = ITOTAL
       GO TO 5
      
C      FORTRAN IV only has do loops
C        DO label variableName = startvalue, endvalue, modificationValue
C        ...
C      label  CONTINUE
C      Loop through and print out the generated fibs

1000   DO 1010 I = 1, ITERS, 1
         WRITE(6, 1001) IARRAY(I)
1001     FORMAT(1X, I5)
1010   CONTINUE

       GO TO 11

9999   WRITE(6, 10000)
       GO TO 99999
       
10000  FORMAT(1X, 'Done.')
99999  STOP
       END
