ON...GOSUB
(Statement)

Call a subroutine depending upon the value of an expression.

ON <expression> GOSUB <labelname>[,<labelname>]...

This statement transfers control to the subroutine beginning with the "nth" <labelname> depending upon the value "n" of <expression>. These <labelname>s are counted, starting from left to right.
If the value of <expression> is real, the system truncates it to an integer "n."

If the operation result of <expression> exceeds the number of <labelname>s, this statement produces nothing.

Use a RETURN statement to return control from the subroutine called by GOSUB (ON...GOSUB) to the caller program.

REM Evaluate more than one condition
|
|
SELECT CASE Index
|
'If the index value and the CASE statement value match,
'the command executes
|
CASE 0
|
'If the index is 0
|
STOP
|
'Stop program execution
|
CASE 1
|
'If the index is 1
|
HALT "STOP"
|
'Stop program execution
|
CASE 2
|
'If the index is 2
|
HOLD "STOP"
|
'Stop program execution temporarily
|
CASE 3
|
'If the index is 3
|
STOPEND
|
'Cycle-stop a continuously executed program
|
CASE 4
|
'If the index is 4
|
ON li1 + li2 GOSUB *samp1, *samp2, *samp3
|
|
|
'Call a subroutine beginning with the nth labelname
'depending upon the value n of li1+li2
|
CASE 5
|
'If the index is 5
|
ON li1 + li2 GOTO *samp1, *samp2, *samp3
|
|
|
'Jump to the nth label depending upon the value n of li1+li2
|
CASE 6
|
'If the index is 6
|
END
|
'Declare the end of motion executed by the program
|
END SELECT
|
'Declare the end of conditions evaluation statement
|