HTBasic Help
×
Menu
Index

IF ... THEN

Performs an action if a condition is true.
 
 IF expression THEN action
 IF expression THEN
   statements
 [ELSE
   statements]
 END IF
 
Usage:
10 IF J2=K THEN 1200
20 IF X=Y THEN Y=Z
30 IF A<0 THEN
40   PRINT "Below Limit!"
50 ELSE
60   CALL Convert
70 END IF
 
Example: IF THEN.BAS
 
Description:
In a single line IF statement, if the expression is true, the action following the THEN is taken. If the expression is false, execution continues with the statement following the IF statement.
 
The following statements are not allowed in single line IF ... THEN statements:
 
CASE
CASE ELSE
COM
DATA
DEF FN
DIM
ELSE
END
END IF
END LOOP
END SELECT
END WHILE
EXIT IF
FNEND
FOR
IF
IMAGE
INTEGER
LOOP
NEXT
OPTION BASE
REAL
REM
REPEAT
SELECT
SUB
SUBEND
UNTIL
WHILE
 
              
To construct a block IF statement, no action is allowed after the THEN on the IF statement and the block structure must end with an END IF statement. Only a block IF allows the optional ELSE statement. If the expression is true, the statements between IF ... THEN and ELSE are executed. Control then continues with the statement following the END IF statement. If the expression is false, the statements between ELSE and END IF are executed.
 
HTBasic also has an explicit ELSE IF statement, but note that it may be preferable to use SELECT CASE.
 
See Also: