User`s guide

Chapter
5
BASIC
Commands
27
5.2 Commands for Decision
Structures
Based on the value of an expression, decision structures cause a program to take one of the
following two actions:
To execute one of several alternative statements within the decision structure itself.
To branch to another part of the program outside the decision structure.
In BASIC, decision-making is handled by the IF...THEN...[ELSE...][ENDIF] and
ON...GOSUB|GOTO...statement.
The IF...THEN...[ELSE...][ENDIF] statement can be used anywhere the
ON...GOSUB|GOTO... statement can be used. The major difference between the two
statements is that ON...GOSUB|GOTO... evaluates a single expression, and then executes
different statements or branches to different parts of the program based on the result. On the
contrary, a block IF...THEN...[ELSE...][ENDIF] can evaluate completely different
expressions. Moreover, the expression given in the ON expression GOSUB|GOTO...
statement must be evaluated by a number in the range 1 to 255, while the expression in
IF...THEN...[ELSE...][ENDIF] statement can only be evaluated as a TRUE or FALSE
condition.
The IF...THEN...[ELSE...][ENDIF] statement can be nested up to 10 levels.
IF ... THEN ... [ELSE...]
Purpose
To provide a decision structure for single-line conditional execution.
Syntax
IF condition THEN action1 [ELSE action2]
Remarks
"condition" is a logical expression.
"action" is a BASIC statement.
Example
IF Data1% > Data2% THEN Temp% = Data1% ELSE Temp% = Data2%
IF ... THEN ... {ELSE IF...} [ELSE...] END IF
Purpose
To provide a decision structure for multiple-line conditional execution.
Syntax
IF condition1 THEN
Statementblock1