IF
Action
Allows conditional execution or branching, based on the evaluation of a Boolean expression.

Syntax
IF expression THEN

[ ELSEIF expression THEN ]
[ ELSE ]

END IF

Remarks

expression Any expression that evaluates to true or false.
New is te ability to use the one line version of IF :
IF expression THEN statement [ ELSE statement ]
The use of [ELSE] is optional.

Also new is the ability to test on bits :
IF var.bit = 1 THEN

In V 2.00 support for variable bit index is added:
Dim Idx as Byte
For IDX = 0 To 7
If P3.IDX = 1 Then
Print "1" ;
Else
Print "0" ;
End if
Next

A new feature in V2 is the ability to use multiple tests:
If a > 10 AND A < 10 OR A = 15 Then

NOP
End if
It does not work with strings yet only numeric conditions.
When you want to test on bytes you can also use the string representation:
Dim X As Byte
If X = "A" then ' normally you need to write :
If X = 65 Then 'so these two lines do the same thing

See also
ELSE , END IF

Example


DIM A AS INTEGER
A = 10
IF A = 10 THEN 'test expression
PRINT " This part is executed." 'this will be printed
ELSE

PRINT " This will never be executed." 'this not
END IF
IF
A = 10 THEN PRINT "New in BASCOM"
IF A = 10 THEN GOTO LABEL1 ELSE PRINT "A<>10"
LABEL1:

REM The following example shows enhanced use of IF THEN
IF A.15 = 1 THEN 'test for bit
PRINT "BIT 15 IS SET"
END IF
REM
the following example shows the 1 line use of IF THEN [ELSE]
IF A.15 = 0 THEN PRINT "BIT 15 is cleared" ELSE PRINT "BIT 15 is set"