IF

The IF statement is used to allow other statements to be conditionally executed.

 

COMMAND SYNTAX

IF expression THEN|ELSE statements

 

SYNTAX ELEMENTS

The expression will be evaluated to a value of Boolean TRUE or FALSE. If the expression is TRUE then the statements defined by the THEN clause will be executed (if present). If the expression is FALSE then the statements defined by the ELSE clause are executed.

The THEN and ELSE clauses may take two different forms being single and multiple line statements.

The simplest form of either clause is of the form:

IF A THEN CRT A

or

IF A ELSE CRT A

but the clauses may be expanded to enclose multiple lines of code using the END keyword as so:

IF A THEN
    A = A*6
    CRT A
END ELSE
    A = 76
    CRT A
END

The single and multi-line versions of either clause may be combined to make complex combinations of the command. For reasons of readability it is suggested that where both clauses are present for an IF statement that the same form of each clause is coded.

 

NOTES

IF statements can be nested within either clause to any number of levels.

 

EXAMPLE

CRT "Are you sure (Y/N) ":
INPUT Answer,1_
IF OCONV(Answer, "MCU")= "Y" THEN
    GOSUB DeleteFiles
    CRT "Files have been deleted"
END ELSE
    CRT "File delete was ignored"
END


jBC