then/else statement blocks are found in conjunction with conditional statements.
then statement.block else statement.block then statement.block else statement.block
The most notable case is the if statement, which requires either a then or an else clause.
The statements that allow or require then and/or else clauses are called initiators. In all statements that allow or require then and/or else:
The possible syntactic structures are:
|initiator then statements else statements
|if ans = "y" then crt "yes" else crt "not yes"
|initiator then statements
|if ans = "y" then crt "yes"
|initiator else statements
|if ans = "y" else crt "not yes"
When both then and else clauses are present, the then clause can be considered to be the initiator of the else clause. All other characteristics are identical, except that an else clause can succeed a then clause.
Within the then clause, the then token is the initiator, which requires a terminator. The clause can exist on one or more than one line. The nature of the terminator varies between these cases.
NULL statements are often included in then or else clauses as placeholders. A NULL statement performs no action. However, you can use NULL statements to make the logic of a conditional more clear and easier to read.
If the then clause is omitted, the statement would make sense to the compiler, but it might not be clear to the user. The NULL statement is used to make clear to the user that if the match returns a value of true, no action is taken.
If the then clause is complete in one physical line, its terminator is an Enter or an else token.
initiator then statements initiator then statements else statements initiator else statements
The syntax of the else clause is the same as that of the then clause, except that it cannot be followed by another else clause.
If the then clause spans more than one physical line, the then token must immediately be followed by an end-of-line (eol) character. This can be either an Enter or a ;. In this case, the clause is terminated by end preceded by an eol character.
initiator then statements statements statements end
There must be one or more statements between the then and its terminator. If there are several statements, they must be separated by eol characters. If the then clause is the one-physical-line clause, the eol character must be a semicolon. If the then clause spans more than one physical line, the eol characters can be either an Enter, a semicolon, or both.
Multiline statements can have more than one end statement. The end statement then becomes the initiator for the else condition as follows:
initiator then statement statement end else statement statement end
Multiple end else sequences can be used, provided that each ends with an end statement.
then statement; statement;...; then statement; statement;...;else
then ; statement; statement; end then ; statement; statement; end else ; statement; statement; end
then statement statement end
For program clarity, the statements are indented from the beginning of the initiator, and the then or end else are aligned with the beginning of the initiator.
IF NUM(PRICE) THEN NULL END ELSE PRINT "ERROR: NON-NUMERIC PRICE. STOP" STOP END
else clause, end statement, get statement, if statement, ifr statement, $chain directive, input statement, key statement, locate statement, lock statement, locked clause, match relational operator, matread statement, null statement, onerr clause, open statement, procread statement, procwrite statement, read statement, readnext statement, readt statement, readtx statement, readv statement, rewind statement, root statement, send statement, statement blocks, then clause, weof statement, \