1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-03 12:21:20 +00:00
QB64-PE/internal/help/ON...GOSUB_11...11111.txt
Roland Heyder aeb9c0668b Updates help files for use with new Wiki parser (2nd try)
Note: Many files were removed (not yet existing/empty pages). The parser will try to download them on demand and will auto-generate text for missing pages (eg. most _gl pages).
2022-05-21 00:18:31 +02:00

58 lines
1.8 KiB
Plaintext

{{QBDLDATE:05-20-2022}}
{{QBDLTIME:23:15:09}}
[[ON...GOSUB]] is a control-flow statement that branches to a line or label in a list depending on a numerical expression.
{{PageSyntax}}
: '''ON''' {{Parameter|numericalExpression}} [[GOSUB]] {{Parameter|labelOrNumber}}[,{{Parameter|labelOrNumber}}][,...]
{{PageDescription}}
* {{Parameter|numericalExpression}} represents the ''line'' or ''label'' that the program should branch to: 1 branches to the first line or label in the list, 2 branches to the second, etc.
* The procedure must be used after the number value is determined or in a loop to monitor current user events.
* [[RETURN]] returns to the next code statement after the [[ON...GOSUB]] statement. [[END]] or [[SYSTEM]] can be used to end program.
* '''Note:''' [[SELECT CASE]] provides a much more convenient way of doing this task.
==QBasic/QuickBASIC==
* In QuickBASIC 4.5 the list could contain a maximum of 60 line numbers or labels, while '''QB64''' has no limit.
{{PageExamples}}
''Example:''
{{CodeStart}}
{{Cl|CLS}}
a = 2
''ON'' a '''GOSUB''' hello, hereweare, 143
{{Cl|PRINT}} "Also notice the RETURN statement that can be used with GOSUB!"
{{Cl|END}}
hello:
{{Cl|PRINT}} "Hello, with a = 1 you get to see this!"
{{Cl|END}}
hereweare:
{{Cl|PRINT}} "with a = 2 here we are...return to line after ON."
{{Cl|RETURN}}
143
{{Cl|PRINT}} "Line 143, with a = 3 you get to see this!"
{{Cl|END}}
{{CodeEnd}}
{{OutputStart}}
with a = 2 here we are...return to line after ON.
Also notice the RETURN statement that can be used with GOSUB!
{{OutputEnd}}
:''Explanation:'' Since ''a'' equals to 2 it goes to the second item in the list (''hereweare'') and branches the program to there. Try changing 'a' to 1 or 3.
{{PageSeeAlso}}
* [[ON...GOTO]]
* [[GOSUB]], [[GOTO]]
* [[SELECT CASE]], [[RETURN]]
{{PageNavigation}}