basic.then/else.construct Definition/BASIC Program

basic.then/else.construct

Command basic.then/else.construct Definition/BASIC Program
Applicable release versions: AP, R83
Category BASIC Program (486)
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.
Syntax then statement.block
else statement.block
then statement.block else statement.block
Options
Example
Purpose
Related basic.procwrite
basic.send
basic.readtx
basic.matread
basic.onerr
basic.readt
basic.readv
basic.null
basic.readnext
statement.block
basic.root
basic.open
basic.weof
basic.else
basic.writet
basic.if
basic.lock
basic.match
basic.rewind
basic.procread
basic.locked
basic.read
basic.readtl
basic.then
basic.end
basic.get
basic.locate
basic.in
basic.key
basic.input@
basic.ifr