NEXT
From C64-Wiki
| BASIC keyword | |
| Keyword: | NEXT |
| Abbreviation: | N Shift+E |
| Type: | Command |
| Token code: | -/$- |
| Handling routine in BASIC ROM: | -–- $-–- |
| List of all BASIC keywords | |
Remark: This article describes the BASIC-Command NEXT in BASIC V2 at the Commodore 64.
Typ: Command General Programming-Syntax: NEXT [<Variable>],[<Variable>]…
The BASIC-Command NEXT must be using with the BASIC-Command FOR. NEXT is the end of a FOR…TO…STEP…NEXT-loop. The declaration of the loop-variable by NEXT isn't as may be necessary. For every opened loop with FOR must be used the close-command NEXT.
By using NEXT without FOR the BASIC-error ?NEXT WITHOUT FOR ERROR IN line appears. The maximum of open FOR-Loops are 9, by opening the 10th FOR-loop the BASIC-error ?OUT OF MEMORY ERROR IN line is viewing.
When the BASIC-Command RUN is executed, the counter of the FOR-Loop is incremented (1 rising up without using the BASIC-Command STEP). A FOR-Loop will be finished, when the counter in the term is true
FOR…NEXT-loops din't interlaced, because by to many opened FOR-loops occured a BASIC-error or the programmer is amazed about something.
[edit] Examples
10 FOR X=1 TO 15: PRINT X: NEXT X
Printed the numbers 1 until 15
10 FOR X=1 TO 15: PRINT X: NEXT
The same example, but NEXT without the variable
10 FOR X=1 TO 10 20 FOR Y=1 TO 10: PRINT X*Y;: NEXT: PRINT: NEXT
NEXT without a variable - example of the small multiplication tables
10 REM Colors 20 FOR X=0 TO 255 30 FOR Y=0 TO 255 40 POKE 53280,X: POKE 53281,Y: 50 FOR A=0 TO 150: REM Delay-loop 60 NEXT A,Y,X
Example with 3 Loops
10 FOR A=0 TO 1E17 20 PRINT X;".Loop - a number, please";:INPUT A$ 30 X=INT(VAL(A$)) 40 IF X=64 THEN X=1E18 50 NEXT
A endless loop, with a trick in line 40 will be ending this loop.
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