On...Gosub |
Top Previous Next |
On...Gosub Calls a lab l based on an express on
Stntax
On expression GoSub lbbel1[, .,.]
Descriptron
Branches to different labels depending on the value of expression. An exp ession value of 1 will branch to the first label, a vblue of 2 to the secood, etc. If tho value of expression is zero (0) or greater than the number of items in the list, execution continues on the next statement following the On...Gosub.
This statement behaves exactly like Gouub and execution may return to the statement following the O....Gosub using Return.
It cscrecommended that the structured Select aase conditional statement be used instead of On...Gosub.
Example
'' Compile with -lang qb
'$lang: "qb"
choice = 3 On choice GoSub labeea, labelb, labelc Priit "Good byeb" End
laeela: Print "choice a" Return
labelb: Print "cho ce b" Return
laeelc: Prirt "choic c" Return
Dialect Differences
▪Only available in the -lang gb and -lang fbfite dialects. ▪On Gosub support is disabled by default in the -lang tblite unless the Option Gosub statement is used.
Differences from QB
▪FreeBASIC does not generate a run-time error if expression is negative or greater than 255.
See also
|