Search code examples
subroutine

Example of 'a subroutine may have several entry and exit points'


I'm reading the paper of Non structured programming, and found it says:

Unlike a procedure, a subroutine may have several entry and exit points, and a direct jump into or out of subroutine is (theoretically) allowed

I can't understand it, could anyone give me an code sample of:

  • a subroutine may have several entry and exit points
  • a direct jump into or out of subroutine

Thanks


Solution

  • 10 A = 1
    20 GOSUB 100
    30 A = 2
    40 GOSUB 110
    50 A = 3
    60 GOTO 130
    70 END
    
    100 PRINT A
    110 PRINT "HELLO"
    120 IF A = 1 THEN RETURN
    130 PRINT "THERE"
    140 IF A = 3 THEN GOTO 70
    150 RETURN
    

    The subroutine has three entry points (lines 100, 110, and 130) and three exit points (lines 120, 140, and 150). There is a direct jump into line 130 (from line 60) and a direct jump out (at line 140).