Control structures in programming languages: from goto to algebraic effects

Xavier Leroy

Loops and conditionals in Fortran (chapter 1)

C Fortran control structures - Section 1.3

C The do loop

      DO 100 I = 1, 5
         PRINT *, 'I = ', I
 100  CONTINUE

C A loop based on goto

      J = 2
 200  PRINT *, 'J = ', J
      J = J * 2
      IF (J .LE. 1000) GOTO 200

C Three-way conditional jumps (FORTRAN-I)

      X = -1.23
      Y = X
      IF (X) 701, 702, 702
 701  Y = -Y
 702  PRINT *, 'ABS(', X, ') = ', Y

C Boolean conditional jumps (FORTRAN-IV)

      Y = X
      IF (X .LT. 0) Y = -Y
      PRINT *, 'ABS(', X, ') = ', Y

      IF (X .LT. 0) GOTO 800
      Y = X
      GOTO 801
 800  Y = -X
 801  PRINT *, 'ABS(', X, ') = ', Y

C Conditional statement (FORTRAN-77)

      IF (X .LT. 0) THEN
         Y = -X
      ELSE
         Y = X
      END IF
      PRINT *, 'ABS(', X, ') = ', Y

      STOP

      END