ON...GOTO: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "ON...GOTO is a control-flow statement that branches to a line or label in a list depending on a numerical expression. {{PageSyntax}} : '''ON''' {{Parameter|numericalExpression}} GOTO {{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...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 11: | Line 11: | ||
* '''Note:''' [[SELECT CASE]] provides a much more convenient way of doing this task. | * '''Note:''' [[SELECT CASE]] provides a much more convenient way of doing this task. | ||
=== QBasic/QuickBASIC === | |||
==QBasic/QuickBASIC== | |||
* In QuickBASIC 4.5 the list could contain a maximum of 60 line numbers or labels, while '''QB64''' has no limit. | * In QuickBASIC 4.5 the list could contain a maximum of 60 line numbers or labels, while '''QB64''' has no limit. | ||
Line 18: | Line 17: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' Changing the program flow when a value is not 0. | ''Example:'' Changing the program flow when a value is not 0. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|CLS}} | {{Cl|CLS}} | ||
a = 2 | a = 2 | ||
Line 31: | Line 30: | ||
143 | 143 | ||
PRINT "you don't get to see this neither..." | PRINT "you don't get to see this neither..." | ||
END | END | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} |
Latest revision as of 02:07, 28 January 2023
ON...GOTO is a control-flow statement that branches to a line or label in a list depending on a numerical expression.
Syntax
- ON numericalExpression GOTO labelOrNumber[,labelOrNumber][,...]
Description
- 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.
- 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.
Examples
Example: Changing the program flow when a value is not 0.
CLS a = 2 ON a GOTO hello, hereweare, 143 END hello: PRINT "you don't get to see this!" END hereweare: PRINT "And here we are..." END 143 PRINT "you don't get to see this neither..." END |
And here we are... |
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.
See also