intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF (EN)

int e l 4.15 DESCRIPTION OF STATEMENTS STATEMENTS: IF -- THEN -- ELSE MODE: RUN TYPE: CONTROL The IF statement sets up a conditional test. The generalized form of the IF -- THEN -- ELSE statement is as follows: [ln num] IF [rel expr] THEN valid STATEMENT ELSE valid STATEMENT A specific example is as follows: >10 IF A=100 THEN A=0 ELSE A=A+1 Upon execution of line 10 IF A is equal to 100, THEN A would be assigned a value of 0. IF A does not equal 100, A would be assigned a value of A + 1 . If it is desired to transfer control to different line numbers using the IF statement, the GOTO statement may be omitted. The following examples would yield the same results:

>20 IF INT(A) >20 IF INT(A) Additionally, the THEN statement can be replaced by any valid MCS BASIC-52 statement, as shown below: >30 IF A 10 THEN PRINT A ELSE 10 >30 IF A 10 PRINT A ELSE 10 The ELSE statement may be omitted. If it is, control will pass to the next statement. EXAMPLE: >20 IF A=10 THEN 40 >30 PRINT A In this example. IF A equals 10 then control would be passed to line number 40. If A does not equal 10 line number 30 would be executed. - 45 -