basic.then/else.construct

Definition/BASIC Program, Releases: AP and R83

provide program flow change based upon a boolean condition.

Syntax

then statement.block else statement.block then statement.block else statement.block

Description

are found in conjunction with conditional statements.

The most notable case is the 'if' statement, which requires either a 'then' or an 'else' clause.

In all statements which allow or require 'then' and/or 'else', the 'then' branch is taken if the operation is performed successfully, or a 'true' is returned. The 'else' clause is taken when the operation is unsuccessful, or 'false' is returned.

For purposes of our documentation, we will call all the statements which allow or require 'then' and/or 'else' clauses 'initiators'.

The possible syntactic structures are:

1) initiator then statements else statements

example: if ans = 'y' then crt 'yes' else crt 'not yes'

2) initiator then statements

example: if ans = 'y' then crt 'yes'

3) initiator else statements

example: if ans = 'y' else crt 'not yes'

When both 'then' and 'else' clauses are present, the 'then' clause may be considered to be the initiator of the 'else' clause. All other characteristics are identical, except that an 'else' clause may succeed a 'then' clause.

Within the 'then' clause, the 'then' token is the initiator, which requires a terminator. The clause may exist on one or more than one line. The nature of the terminator varies between these cases.

The Single-line form:

If the 'then' clause is complete in one physical line, its terminator is a <return> or an 'else' token.

1) initiator then statement{s}<return>

2) initiator then statement{s} else statement{s}<return>

3) initiator else statement{s}<return>

The form for the single-line clause:

then statement; statement; ... ;<return>
-or-
then statement; statement; ... ;else<return>

The syntax of the 'else' clause is the same as that of the 'then' clause, except that it may not be followed by another 'else' clause.

The Multi-line form:

If the 'then' clause spans more than one physical line, the 'then' token must immediately be followed by an eol (end-of-line) character. This may be either a <return> or a ';' (semi-colon). In this case, the clause is terminated by 'end' preceded by an eol character.

initiator then<return>
statement{s}<return>
statement{s}<return>
statement{s}<return>
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 semi-colon. If the then clause spans more than one physical line, the eol characters may be either (or both) <return>'s or semi-colons.

The form of the multi-line clause:

1) then eol statement eol statement eol eol end eol

2) then eol statement eol statement eol eol end else eol statement eol statement eol end

In this case, each eol character may be either a <return> or a semi-colon. This means that a multi-line clause may be contained in either one or more than one physical line. This case will normally appear as:

then<return>
statement<return>
statement<return>
statement<return>
end<return>

For program clarity, the statements are indented from the beginning of the initiator, and the 'then' or 'end else' are outdented to the beginning of the initiator.

Multiple end statements:

Multi-line statements may have more than one 'end' statement. The 'end' statement then becomes the initiator for the 'else' condition as follows:

initiator then<return>
statement<return>
statement<return>
statement<return>
end else<return>
statement<return>
statement<return>
statement<return>
end

Multiple 'end else' sequences may be used, provided that each ends with an 'end' statement.

Historical Development of the then/else clause

Early in the development of Pick, some statements required 'else' clauses, such as the 'read' statement. This provided the ability of taking a separate 'pathway' through the program if the item being read was NOT found.

Later, the 'then' clause was introduced and the rules changed. Under this new provision, statements like 'read' can have a 'then' and/or an 'else' clause, but one or the other had to be present.

In AP, the rules changed again. The 'read' statement still supports 'else' and 'then' clauses, but neither is required. Some statements, such as 'if', still require one or the other.

See Also

Command Name Type Description
basic.procwrite Statement Writes primary input buffer.
basic.send Statement Sends output to a specific port.
basic.readtx Statement Reads one tape record and displays in hexadecimal.
basic.matread Statement Reads item into dimensioned array.
basic.onerr Definition Takes 'error' path when media error encountered.
basic.readt Statement Reads one tape record.
basic.readv Statement Reads one attribute and assigns to value.
basic.null Statement No-op compiler directive.
basic.readnext Statement Retrieves the next item-id from an active list.
statement.block Definition one or more statements that follow a Pick/BASIC decision-path related token such as, but not limited to, 'then', 'else', 'locked' and 'onerr'.
basic.root Statement Loads the root.variable with the root FID of the specified index.
basic.open Statement Opens file for input and output.
basic.weof Statement Writes an end-of-file mark to tape.
basic.else Statement In-line initiator.
basic.writet Statement Writes a string to magnetic media.
basic.if Statement Initiates logical expression.
basic.lock Statement Sets execution lock.
basic.match Relational Operator Pattern matching function.
basic.rewind Statement Rewinds magnetic media.
basic.procread Statement Reads primary input buffer.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.