2

I encounter a strange behaviour in Fortran 77 code (gfortran compiler), the following line works perfectly (jumping to label 202 for iprob=202):

      if( iprob .eq. 202 ) goto 202
      !...some commands...
  202 continue

However, its counterpart:

      GO TO ( 202 ), iprob
      !...some commands...
  202 continue

doesn't. The program just runs through for iprob=202.

Maybe anybody has an idea on that issue?

francescalus
  • 30,576
  • 16
  • 61
  • 96
user92202
  • 21
  • 2
  • Are you saying that, in the computed goto case, `iprob` has value `202`, not `1`? – francescalus Aug 22 '16 at 09:44
  • Yes, iprob=202 in both cases. I am aware of the documentation and can't find anything wrong in the computed go-to case. Thus I am puzzled, why it fails. Potentially there is an error somewhere else, but I didnt see it so far. – user92202 Aug 22 '16 at 09:55
  • My mistake! I missunderstood the command, for iprob=1 it jumps. Sorry for the confusion – user92202 Aug 22 '16 at 10:04

1 Answers1

3

The form

go to ( 202 ), iprob

is a computed go to statement. In such a statement there is a list of labels (here just the one 202) and an integer expression (here iprob) which selects the label.

Label selection is by order in the list. So, to select the first label the value of the expression should be 1. With iprob having the value 202 the 202nd label (if it exists) would be selected. With the integer expression out of range (less than 1, more than the number of labels in the list) execution continues on to the next line. Running through the goto, as you have it.

You may be thinking of assigned go to statements, where the label is determined by the value of an expression. I won't go into details of that, though, as it is no longer part of the Fortran standard.

Graham
  • 7,431
  • 18
  • 59
  • 84
francescalus
  • 30,576
  • 16
  • 61
  • 96