On…GoSub Command

Evaluates and truncates the expression to an integer. If the resulting value is 0, performs a GoSub to label0; if 1, goes to label1; and so on.

Syntax

On expression GoSub label0, label1, ...

where the label parameters are defined by the Label command.

Remarks

If the value is less than 0 or greater than or equal to the number of labels, no subroutine call is performed and execution continues to the next command. This does not cause an error.

Example

DECLARE iSeg

FOR iSeg = 1 TO 4

ON iSeg GOSUB subSeg1, subSeg2, subSeg3, subSeg4

NEXT iSeg

SubSeg1:

'Some code…

RETURN

SubSeg2:

'Some code…

RETURN

SubSeg3:

'Some code…

RETURN

SubSeg4:

'Some code…

RETURN