GOTO
Jump to navigation
Jump to search
Navigation:
The GOTO statement sends the procedure to a line label or a line number in the program.
Contents
Syntax
- GOTO {lineNumber|lineLabel}
IF Syntax:
- IF condition GOTO {lineNumber|lineLabel}
Description
- lineNumber or lineLabel 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 and it could also cause endless loops.
- GOTO is an easy trap for new programmers. Use loops instead when possible.
Examples
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
- GOSUB, ON ERROR
- ON...GOTO, ON...GOSUB
- DO...LOOP, FOR...NEXT
- IF...THEN, SELECT CASE
- Line numbers and labels