Original Author Paul Laughton, 2011
Page 79
De Re BASIC!
...
<statement> }
{ ELSE
<statement>
<statement>
...
<statement> }
ENDIF
If commands may be nested to any depth. That is, any <statement> in a block may be a full If command
with all of its own <statement> blocks.
See the Sample Program file, F04_if_else.bas, for working examples of the If command.
If / Then / Else
If your conditional block(s) contain(s) only one statement, you may use a simpler form of the If
command, all one line:
IF <condition> THEN <statement> { ELSE <statement> }
In this form, Then is required, and there is no ElseIf or EndIf.
This form does not nest: neither <statement> may be an If command.
Because the single statements are not treated as blocks, this is the preferred form if either of the
embedded statements is a Break, Continue, or GoTo.
You may replace either <statement> with multiple statements separated by colon (":") characters. If you
do this, the set of multiple statements is treated as a block, and the single-line If/Then/Else becomes an
If/Then/Else/Endif. These two lines are exactly equivalent:
IF (x > y) THEN x = y : PRINT a$ ELSE y = x : PRINT b$
IF (x > y) : x = y : PRINT a$ : ELSE : y = x : PRINT b$ : ENDIF
Please note, if you wish to use colon-separated statements in this form of If/Then/Else, then you must
be careful to put spaces around the keywords Then and Else. Spaces are not significant to the BASIC!
interpreter, but they are needed by the preprocessor that converts the single-line If with multi-
statement blocks into a multi-line If with an EndIf.
For - To - Step / Next
FOR <nvar> = <nexp_1> TO <nexp_2> {STEP <nexp_3>}
<statement>
...
<statement>
NEXT {<nvar>}