



Unconditional GO TO Statement GO TO statement simply produces a transfer of control to a
labelled executable statement elsewhere in the program unit. Its general form
is:
GO TO label
Note that control must not be transferred into an IF-block or a DO-loop from outside
it.
The unconditional GO TO statement makes it possible to construct programs with
a very undisciplined structure; such programs are usually hard to understand and to
maintain. Good programmers use GO TO statements and labels very sparingly.
Unfortunately it is not always possible to avoid them entirely in Fortran because of a
lack of alternative control structures.
The next example finds the highest common factor of two integers M and N using a Euclid's algorithm. It can be expressed roughly: while (M N) subtract the smaller of M and N from the other repeat until they are equal.
PROGRAM EUCLID WRITE(UNIT=*, FMT=*) 'Enter two integers' READ(UNIT=*, FMT=*) M, N 10 IF(M .NE. N) THEN IF(M .GT. N) THEN M = M - N ELSE N = N - M END IF GO TO 10 END IF WRITE(UNIT=*, FMT=*)'Highest common factor = ', M END |