33
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
IF … THEN … {ELSE IF…} [ELSE…] END IF
Purpose To provide a decision structure for multiple-line conditional execution.
Syntax IF condition1 THEN
Statementblock1
{ELSE IF condition2 THEN
Statementblock2}
[ELSE
StatementblockN]
END IF
Remarks “condition” is a logical expression.
“Statementblock” can be multiple lines of BASIC statements.
Example
IF LEFT$(String1$, 1) = “A” THEN
PRINT “String1 is led by A.”
ELSE IF LEFT$(String1$, 1) = “B” THEN
PRINT “String1 is led by B.”
ELSE
PRINT “String1 is not led by A nor B.”