1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 16:10:39 +00:00
QB64-PE/internal/help/ON...GOTO.txt

51 lines
1.4 KiB
Plaintext
Raw Normal View History

2019-04-15 01:15:33 +00:00
[[ON...GOTO]] is a control-flow statement that branches to a line or label in a list depending on a numerical expression.
{{PageSyntax}}
2019-04-15 01:15:33 +00:00
: '''ON''' {{Parameter|numericalExpression}} [[GOTO]] {{Parameter|labelOrNumber}}[,{{Parameter|labelOrNumber}}][,...]
2019-04-15 01:15:33 +00:00
{{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.
2019-04-15 01:15:33 +00:00
* '''Note:''' [[SELECT CASE]] provides a much more convenient way of doing this task.
==QBasic/QuickBASIC==
2019-04-15 01:15:33 +00:00
* In QuickBASIC 4.5 the list could contain a maximum of 60 line numbers or labels, while '''QB64''' has no limit.
{{PageExamples}}
''Example:'' Changing the program flow when a value is not 0.
{{CodeStart}} '' ''
{{Cl|CLS}}
a = 2
2016-03-18 11:36:04 +00:00
{{Cl|ON...GOTO|ON a GOTO}} hello, hereweare, 143
{{Cl|END}}
hello:
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} "you don't get to see this!"
{{Cl|END}}
hereweare:
2019-04-15 01:15:33 +00:00
PRINT "And here we are..."
END
143
2019-04-15 01:15:33 +00:00
PRINT "you don't get to see this neither..."
END '' ''
{{CodeEnd}}
{{OutputStart}}
And here we are...
{{OutputEnd}}
2019-04-15 01:15:33 +00:00
''Explanation:'' Since ''a'' equals 2 it goes to the second item in the list (hereweare) and branches to there. Try changing ''a' to 1 or 3.
2019-04-15 01:15:33 +00:00
{{PageSeeAlso}}
* [[ON...GOSUB]]
* [[GOTO]]
* [[GOSUB]]
* [[SELECT CASE]]
2019-04-15 01:15:33 +00:00
{{PageNavigation}}
<