GoSub Command

Purpose

Branches to and returns from a subroutine within procedure.

Syntax

GoSub label
...
label:
...
Return

Description

You can use GoSub and Return anywhere in a procedure, but GoSub and the corresponding Return statement must be in the same procedure. A subroutine can contain more than one Return statement, but the first Return statement encountered causes the flow of execution to branch back to the statement immediately following the most recently executed GoSub statement.

You can't enter or exit Sub procedures with GoSub...Return.

Example

OpenW 1

test_mark // call Procedure

Do : Sleep : Until Me Is Nothing

CloseW # 1

 

Procedure test_mark

Text 50, 20, "Hallo"

GoSub mar1

GoSub mar2

GoSub mar3

Text 250, 50, "GmbH"

Return

mar1:

Text 50, 50, "GFA"

Return

mar2:

Text 80, 50, "Software"

Return

mar3:

Text 160, 50, "Technologies"

EndProc

Known Error

There is an obscure error involving a Boolean passed to Variant parameters from procedures containing a Gosub...Return construct. See here for more details.

Remarks

A label might consist of a number (10) or start with alphanumeric character followed by more characters and ended with a semi-colon (p2:).

The label has function scope and cannot be redeclared within the function. However, the same name can be used as a label in different functions.

See Also

On Gosub, Goto

{Created by Sjouke Hamstra; Last updated: 11/03/2018 by James Gaite}