0

I am working on Fortran Code. While analyzing the code, I noticed something like this:

SUBROUTINE TEST(I,Z)
...
...
SELECT CASE (Z)
  CASE(:1)
     bla bla Code
     IF(a.GT.b) GO TO 220
  CASE(:2)
     bla bla Code
     IF(c.GT.d) GO TO 220
  CASE(:3)
     bla bla Code
     IF(e.GT.f) GO TO 220

Code goes on...
Code goes on...

220  RETURN

Code goes on... 

RETURN
END 
     

What I do not get: what does the RETURN "command" stand for/doing?

For the algorithm it is important that Case1, Case2 and Case3 are excecuted. So my guess is, that if the if condition is true, it jumps from e.g. Case1 to RETURN, what could mean: leave the subroutine. In this case : go on with CASE2. But then one could directly say: GO TO ...next case.

I have nothing found in the World Wide Web. Can someone help me?

Thanks :-)

Helmut K.
  • 51
  • 1
  • 1
  • 2
  • It returns from the subroutine. The code that follows won't be executed unless there's a goto in the code prior that jumps to that following code. – L. Scott Johnson Jul 13 '20 at 11:50
  • Hi Scott, so if I understand you right: for CASE(:1) , if a > b , it jumps to 220 (RETURN) what means that the subroutine is left / exit. So CASE(:2) and CASE(:3) will be ignored. – Helmut K. Jul 13 '20 at 12:50
  • 1
    The `return` makes the code leave the subroutine at that point - there's nothing special about it being in a select case construct. Note that the `goto 220` seems a bit useless in the fragment you show: once the block of the case is reached the block construct is left. It isn't like C where cases fall through. Exactly one case is performed. – francescalus Jul 13 '20 at 16:12
  • Specifically, it could just be `IF(a.GT.b) RETURN` and nothing changes. Depending on what is omitted in your snippet, more simplification might be possible. – Vladimir F Героям слава Jul 13 '20 at 17:56

0 Answers0