Return Statement

The Return statement is used with the GoSub statement. GoSub transfers program control to a subroutine. Once the subroutine is complete, Return causes program execution to continue at the line following the GoSub instruction which initiated the subroutine.

Syntax
Return

Description
The Return statement is used with the GoSub statement. The primary purpose of the Return statement is to return program control back to the instruction following the GoSub instruction which initiated the subroutine in the first place.

The GoSub instruction causes program control to branch to the user specified statement line number or label. The program then executes the statement on that line and continues execution through subsequent line numbers until a Return instruction is encountered. The Return instruction then causes program control to transfer back to the line which immediately follows the line which initiated the GoSub in the first place. (i.e. the GoSub instruction causes the execution of a subroutine and then execution Returns to the statement following the GoSub instruction.)

Potential Error

  • Return Found Without GoSub

    A Return instruction is used to "return" from a subroutine back to the original program which issued the GoSub instruction. If a Return instruction is encountered without a GoSub having first been issued then an error will occur. A standalone Return instruction has no meaning because the system doesn't know where to Return to.

See Also
OnErr, GoSub, GoTo

Return Statement Example
The following example shows a simple function which uses a GoSub instruction to branch to a label called checkio and check the first 16 user inputs. Then the subroutine returns back to the main program.

Function main
     Integer var1, var2
     GoSub checkio
     On 1
     On 2
     Exit Function

checkio:     'Subroutine starts here
     var1 = In(0)
     var2 = In(1)
     If var1 <> 0 Or var2 <> 0 Then
          Print "Message to Operator here"
     EndIf
finished:
     Return  'Subroutine ends here and returns to line 40
Fend