GLBasic User Manual

Main sections

IF

IF a#$ = < <= > >= <> b#$
...
| ELSEIF ...
| ...
| ELSE
| ...
ENDIF



or:

IF a#$ = < <= > >= <> b#$ THEN ...



An IF statement allows for a block of code to be executed if a certain condition (a#...b#) is found to be true - i.e. it executes the code between the IF and ENDIF statements if the particular comparison of variables a#$ and b#$ is TRUE. If the comparision evaluates to FALSE, the code between ELSE and ENDIF is executed (provided an ELSE statement was supplied).

Using an ELSEIF command allows you to add another test to perform if the previous test condition evaluated to false:
IF a>5
PRINT "a>5", 0,0
ELSEIF b>5
PRINT "a<=5, but b>5", 0,0
ELSE
PRINT "Neither a nor b > 5", 0,0
ENDIF


You can use the command THEN if you only want one command to be executed if the comparison is TRUE.

Sample:
 
a=5; b=3

IF a < b
PRINT "a < b", 100, 100
ELSE
PRINT "a < b is FALSE", 100, 100
ENDIF

IF a<>b THEN PRINT "a is not b", 100, 150

SHOWSCREEN
MOUSEWAIT


Output:
a < b is FALSE
a is not b

See also...