ON...GOTO - QB64 Wiki

ON...GOTO

From QB64 Wiki

Jump to: navigation, search

ON...GOTO is a control-flow statement that branches to a line number or label in a list depending on a numerical expression's value.


Syntax:

ON numerical-expression GOTO lineornumber[,lineornumber][,...]


  • The numerical-expression represents the line or label that it should branch to, 1 branches to the first line or label, 2 branches to the second, etc.
  • In QB 4.5 the list can contain a maximum of 60 lines or labels, while there is no limit in QB64.
  • The procedure must be used after the number value is determined or in a loop to monitor current user events.


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!

Note: SELECT CASE provides a much more convenient way of doing this task.


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Views
  • Page
  • Discussion
  • View source
  • History
Personal tools
  • Log in
Toolbox
  • What links here
  • Related changes
  • Special pages
  • Printable version