IF

From C64-Wiki

Jump to: navigation, search
BASIC keyword
Keyword:IF
Abbreviation:-
Type:Command
Token code:-/$-
Handling routine
in BASIC ROM:
-–-
$-–-
List of all BASIC keywords


Remark: This article describes the BASIC-Command IF in BASIC V2 at the Commodore 64.

Typ: Command
General Programming-Syntax: IF <equation> THEN <linenumber> 
                               or IF <equation> GOTO <linenumber> 
                               or IF <equation> THEN <command>

The BASIC-Command IF is used together with the BASIC-Command THEN or with the BASIC-Command GOTO by equations. When the equations is right or true, the BASIC-Commands after THEN or the GOTO-Command is running. By a wrong equation the BASIC interpreter will be ignore the following BASIC commands in this line.

For the equantion will be needed this relational operators:

  • = equal
  • <> unequal
  • < less than
  • > greater
  • <= less-equal
  • >= greater-equal

Furthermore can be used logical operators like AND, OR or NOT and by using more than one equations for combining or seperating, can be used brackets ().

[edit] Examples

10 PRINTCHR$(147);
20 INPUT "2 numbers, please: ";A$, B$
30 IF A$="" OR B$="" THEN 20
40 A=VAL(A$): B=VAL(B$)
50 IF A>0 THEN PRINT "A is posotiv and ";
51 IF A<0 THEN PRINT "A is negativ and ";
52 IF A=B THEN PRINT "A is equal B ";
53 IF A<>B THEN PRINT "A is unequal B ";
54 IF NOT A AND NOT B THEN PRINT ", no number value is -1";
55 IF A=64 AND B=64 THEN PRINT " !!! BINGO !!!": GOTO 58
56 IF A=B AND A=0 GOTO 58
57 IF (A AND B=0) OR (NOT B AND A=0) THEN END
58 FOR X=0 TO 3000: NEXT
59 GOTO 10
BASIC V2.0-Commands of Commodore 64

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

 
Personal tools
Help and Feedback
In other languages