GOTO - QB64 Wiki

GOTO

From QB64 Wiki

Revision as of 01:33, 23 December 2015 by Clippy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The GOTO statement sends the procedure to a line label or a line number in the program.


Syntax:

GOTO {line_number|line_label}


IF GOTO Syntax:

IF x > 0 GOTO {line_number|line_label}


  • Codeline is a linenumber or linelabel in a procedure. Keep line numbers and labels inside of the main or sub-procedure body!
  • The line label or number MUST already exist or an IDE status error will be displayed until it is created!
  • Can be used in SUB or FUNCTION procedures using their own line labels or numbers.
  • The frequent use of GOTO statements can become confusing when trying to follow the code. Could also cause endless loops!
  • GOTO is an easy trap for new programmers. Use loops instead when possible.


Example:

1 PRINT "first line": GOTO gohere 2 PRINT "second line": GOTO 3 gohere: PRINT "third line" GOTO 2 3 END

first line third line second line

Explanation: After it prints "first line" it goes to the line label "gohere" where it prints "third line", then it goes to the line that is numbered "2" and prints "second line" and goes to line number 3 and an END statement which ends the program.


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Views
Personal tools