GOTO
From C64-Wiki
| BASIC keyword | |
| Keyword: | GOTO |
| Abbreviation: | G Shift+O |
| Type: | Command |
| Token code: | 137/$89 |
| Handling routine in BASIC ROM: | 43168–43217 $A8A0–A8D1 |
| List of all BASIC keywords | |
Remark: This article describes the BASIC-Command GOTO in BASIC V2 at the Commodore 64.
Typ: Command General Programming-Syntax: GOTO <line>
The BASIC command GOTO makes the BASIC interpreter jump to the indicated line and the execution of the BASIC program is continued at that line.
With the BASIC command GOTO infinite loops can be programmed. The code 55 GOTO 55 can only be stopped by pushing the key <RUN/STOP>.
The BASIC command GOTO can be used directly to start a programm at a specified line number like the BASIC command RUN <line>. Difference is that RUN clears variable values before starting the program, which GOTO does not.
When the targeted line number doesn't exist, the BASIC error ?UNDEF'D STATEMENT ERROR IN line occurs.
[edit] Examples
10 C=0: PRINT CHR$(147);: INPUT "Input a number, please "; A 20 PRINT "Input a second number, please "; 30 INPUT B: IF C=1 AND B=0 GOTO 30 31 IF C=1 AND B<>0 GOTO 74 40 C=1: INPUT "Input an arithmetic operator (+-/*) "; A$ 50 IF A$<>"+" OR A$<>"-" OR A$<>"*" OR A$<>"/" GOTO 30 60 IF B=0 AND A$="/" THEN PRINT "Division by 0 is not allowed, correction:";: GO TO 30 70 IF A$="+" THEN C=A+B: B$="ADDITION" 71 IF A$="-" THEN C=A-B: B$="SUBTRACTION" 72 IF A$="*" THEN C=A*B: B$="MULTIPLICATION" 73 IF A$="/" THEN C=A/B: B$="DIVISION" 74 PRINT "Your choice: " B$ 75 PRINT "The output is: " C 80 INPUT "Another calculation (Y=YES, End with other chars)"; A$ 90 IF A$="Y" THEN GOTO 10
Demonstration of direct GOTO vs. RUN contrast:
10 INPUT A 20 PRINT A A=7:GOTO20 7 READY. A=7:RUN20 0 READY.
ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC( | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB( | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT