home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4422 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  1.6 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!uwm.edu!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!burley
  2. From: burley@apple-gunkies.gnu.ai.mit.edu (Craig Burley)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Multiple returns (was: Jumping from nested subs to main directly)
  5. Date: 23 Nov 92 11:08:26
  6. Organization: Free Software Foundation 545 Tech Square Cambridge, MA 02139
  7. Lines: 54
  8. Message-ID: <BURLEY.92Nov23110826@apple-gunkies.gnu.ai.mit.edu>
  9. References: <1992Nov23.021053.11218@netcom.com>
  10. NNTP-Posting-Host: apple-gunkies.gnu.ai.mit.edu
  11. In-reply-to: jchauvin@netcom.com's message of Mon, 23 Nov 1992 02:10:53 GMT
  12.  
  13. In article <1992Nov23.021053.11218@netcom.com> jchauvin@netcom.com (John H. Chauvin) writes:
  14.  
  15.    PROGRAM EXAMPLE
  16.    CALL SUB1
  17.    .
  18.    .
  19.    .
  20.    STOP
  21.    END
  22.    SUB1
  23.    CALL SUB2
  24.    A=A+1
  25.    END
  26.    SUB2
  27.    CALL SUB3
  28.    END
  29.    SUB3
  30.  
  31.    EXIT 2 (Returned to statement A=A+1 in one call)
  32.  
  33.    END
  34.  
  35. Why won't RETURN work?  It'll return to the END in SUB2, which'll return
  36. to A=A+1 in SUB1.
  37.  
  38. Now, if you meant to imply that SUB2's call to SUB3 might be followed by
  39. other stuff you don't want to happen...try this:
  40.  
  41.    PROGRAM EXAMPLE
  42.    CALL SUB1
  43.    .
  44.    .
  45.    .
  46.    STOP
  47.    END
  48.    SUBROUTINE SUB1
  49.    CALL SUB2
  50.    A=A+1
  51.    END
  52.    SUBROUTINE SUB2
  53.    CALL SUB3(*99)
  54.    ...other stuff I don't want to happen if SUB3 wants to "jump" back to SUB1
  55. 99 END
  56.    SUBROUTINE SUB3(*)
  57.  
  58.    RETURN 1  (Return to statement label passed for first "*" in arglist)
  59.  
  60.    END
  61.  
  62. I hope this helps.
  63. --
  64.  
  65. James Craig Burley, Software Craftsperson    burley@gnu.ai.mit.edu
  66. Member of the League for Programming Freedom (LPF) lpf@uunet.uu.net
  67.