IF ... END IF
IF is a very powerful control flow sentence that allows you to make decisions under specified conditions.
Syntax
or
Examples
Sentences might be in multiple lines:
Since IF is a sentence, it can be nested; however, remember that every IF must be closed with
END IF when the line is split after THEN (mutiline IF):
Using ELSEIF
In the example above, you see that nesting an IF inside another one could be somewhat verbose and error prone. It's better to use the ELSEIF construct. So the previous example could be rewritten as:
Remarks
- This sentence is extended allowing now multiline IFs and also compatible with the Sinclair BASIC version.
- Starting from version 1.8 onwards the trailing END IF is not mandatory for single-line IFs, for compatibility with Sinclair BASIC
- The THEN keyword can be omitted, but keep in mind this might reduce code legibility.