DO (BASIC 3.5)

From C64-Wiki
(Redirected from DO)
Jump to navigationJump to search
BASIC keyword
Keyword: DO
Abbreviation: None
Type: Command
Token code: UNK
Handling routine
in BASIC ROM:
UNK
List of all BASIC keywords


Remark: This article describes the BASIC command DO in Commodore BASIC V3.5.

Type: Command
General Programming-Syntax: 
  DO [UNTIL boolean argument WHILE boolean argument] statements [EXIT]
  LOOP [UNTIL boolean argument WHILE boolean argument]

DO is a BASIC 3.5 command that is used for performing a loop.

Performs the statements between the DO statement and the LOOP statement. If no UNTIL or WHILE modifies either the DO or the LOOP statement, execution of the intervening statements continues indefinitely.

If an EXIT statement is encountered in the body of the DO loop, execution is transferred to the first statement following the LOOP statement.

DO loops may be nested, following the rules defined for FOR-NEXT loops.

If the UNTIL parameter is used, the program continues looping until the boolean argument is satisfied (becomes TRUE).

The WHILE parameter is basically the opposite of the UNTIL parameter: the program continues looping as long as the boolean argument is TRUE.

Examples[edit | edit source]

 DO UNTIL X=0 OR X=1
 .
 IF X=5 THEN EXIT
 .
 LOOP


 DO WHILE A$="":GET A$:LOOP


DO:J=JOY(1):LOOP UNTIL J

In this example, the loop is executed until the joystick is moved into port 1 or its fire button is pressed.

10 I=1
20 DO:PRINT I,PEEK(124)+256*PEEK(125):I=I+1:GOTO 20

In this program DOs are nested until an ?OUT OF MEMORY ERROR occurs. Output for each run is the nesting depth and the lower limit of the BASIC stack (the PEEK addresses are for the C264 computers, for the C128 the addresses are 125/126).

BASIC V3.5 Commands

ABS | ASC | ATN | AUTO | BACKUP | BOX | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLOR | CONT | COPY | COS | DATA | DEC | DEF | DELETE | DIM | DIRECTORY | DLOAD | DO | DRAW | DS | DS$ | DSAVE | END | EL | ELSE | ER | ERR$ | EXIT | EXP | FN | FOR | FRE | GET | GET# | GETKEY | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | LOOP | MID$ | MONITOR | NEW | NEXT | ON | OPEN | PAINT | PEEK | POKE | POS | PRINT | PRINT USING | PRINT# | PUDEF | RCLR | RDOT | READ | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RLUM | RND | RUN | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SOUND | SPC | SQR | SSHAPE | STOP | STR$ | SYS | TAB | TAN | TRAP | TROFF | TRON | UNTIL | USR | VAL | VERIFY | VOL | WHILE | WAIT