next up previous contents
Next: Assign GOTO Up: GOTO Statements Previous: Unconditional GOTO

   
Computed GOTO

The second form of the GOTO is the COMPUTED GOTO. It has the form :-
GOTO (List of statement labels) expression
For example :-
GOTO (10,23,10,50) I
If I has the value 1 then the program jumps to statement 10, if it has the value 2 it goes to 23 and so on. If I has a value less than 1 or greater than the number of labels in the list the GOTO is ignored. If the expression is a real it is converted to an integer before testing.
Exercise 5
Type in the following program to show the use of the computed GOTO.
        PRINT *,'PLEASE TYPE A NUMBER BETWEEN 1 AND 3'
10      READ *,I
        GOTO (20,30,40) I
        PRINT *,'YOU ARE NOT PAYING ATTENTION, TRY AGAIN!'
        GOTO 10
20      PRINT *,'YOU TYPED ONE'
        STOP
30      PRINT *,'YOU TYPED TWO'
        STOP
40      PRINT *,'YOU TYPED THREE'
        STOP
        END

Note that here is a program with several STOP statements.

* * *



n west (APC)
2000-03-08