bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
GOSUB and RETURN Statement Programming Example
                       ◄Example►                 ◄Contents►  ◄Index►  ◄Back►
──────────────────────────────────────────────────────────────────────────────
'This example uses the GOSUB and RETURN statements to branch to and return
'from a subroutine with and without using linelabel statements.
 
CLS
GOSUB PrintMessage
PRINT "This message is in module-level code"
GOSUB Sub1
PRINT "This line in module-level code should be skipped."
Label1:
PRINT "This message is back in module-level code"
END
 
PrintMessage:
    PRINT "This program illustrates use of the GOSUB and RETURN statements."
    PRINT
    RETURN
 
Sub1:
   PRINT "This message is in Sub1."
   GOSUB Sub2
   PRINT "This line in Sub1 should be skipped."
Label2:
   PRINT "This message is back in Sub1."
   RETURN Label1
 
Sub2:
   PRINT "This message is in Sub2."
   RETURN Label2   'Cannot return from here to main program - only to SUB1.