IF...THEN...ELSE                                                 Statement

IF condition THEN statements [ELSE elsestatements]

IF condition THEN

                [statements]

[ELSEIF condition-n THEN

                [elseifstatements]]...

[ELSE

                [elsestatements]]

END IF

Description

IF...THEN...ELSE is used to conditionally execute a group of statements. The required component, condition, can be any expression that evaluates to TRUE or FALSE. If used inline with no else clause, the statements component is required, otherwise, the statements component is optional. If condition evaluates to TRUE or non-zero, any existing statements are executed, if condition evaluates to FALSE or zero, execution branches to the next existing ELSEIFclause to evaluate condition-n,ortotheELSE clause if it is included.

To execute multiple statements inline, the statements must be separated by a colon (:). If an inline statement consists of a lone procedure call with no arguments, the procedure must be called with empty parenthesis.

Example

REM IF...THEN...ELSE Example

'IF...THEN...ELSE performs conditional execution

DIM Who

IF TRUE THEN PRINT "TRUE" ELSE PRINT "FALSE"

IF Who = "Al" THEN

       PRINT "Big Al"

ELSEIF Who = "Alien" THEN

       PRINT "Alien Probe"

END IF

Output

TRUE

Related Items

SELECT CASE