GOSUB
自从 3.1
GOSUB Label
跳转到函数中用行标号Label声明的位置。
然后如果遇到
RETURN语句,程序回到GOSUB语句后紧接着的代码处运行。
可以嵌套执行GOSUB调用,直至耗尽内存。
Computed GOSUB
自从 3.19
GOSUB Expression
Since Gambas 3.19,
GOSUB
(or
GOTO
) can take any expression as argument.
This expression must return an integer that represents the label you want to branch.
This integer is obtained by using labels as expression. In that case, a labels is transformed into an integer index representing it (only in the function where the label is defined).
Only labels that are outside of any control structure can be a target of a computed GOTO or GOSUB.
Example
Dim JumpArray As Integer[]
JumpArray = [LABEL_1, LABEL_2, LABEL_3]
GoSub JumpArray[Rand(1, 3)]
Return
LABEL_1:
Print "One !"
Return
LABEL_2:
Print "Two !"
Return
LABEL_3:
Print "Three !"
Return
See also