58
Relations or comparisons used in the IF...THEN statement are the following:
= Equal to
< = Less than or equal to
< > Not equal to
> = Greater than or equal to
< Less than
> Greater than
Examples of how you can use conditions:
IF....THEN A=B
IF....THEN GOTO
IF....THEN GOSUB
IF....THEN PRINT
IF....THEN INPUT
Example:
30 IF X >25 THEN 60
If the condition X>25 is true, the computer is told to go to line 60 (Note: the GOTO is
optional after THEN).
If the condition is not true, that is, if X is not greater than 25, then the computer simply
carries on with the normal line number order in the program. Notice that it is not necessary
to use the ELSE part of the command here, as this is optional.
Example:
10 INPUT A,B
20 IF A > B THEN 50
30 IF A < B THEN 60
40 IF A = B THEN 70
50 PRINT A; “IS GREATER THAN”; B:END
60 PRINT A; “IS LESS THAN”; B: END
70 PRINT A; “IS EQUAL TO”;B
80 END
RUN
? 7 (pick a number)
?? 3 (pick a number)
7 IS GREATER THAN 3