Loglan 82, A micro-manual of the programming language - Basic constructs and facilities

2) Compound Statements


Compound statements in LOGLAN-82 are built up from simple statements (like assignment statement e.g. x:=y+0.5, call statement e.g. call P(7,x+5) etc.) by means of conditional, iteration and case statements.

The syntax of conditional statement is as follows:

where "else part" may be omitted:

The semantics of conditional statement is standard. The keyword fi allows to nest conditional statements without appearence of "dangling else" ambiguity.

Example:

The statements in a sequence of statements are separated with semicolons (semicolon may end a sequence , and then, the last statement in the sequence is the empty statement).

The short circuit control forms are realized in LOGLAN-82 by the conditional statements with orif (or andif) list. A conditional statement with orif list has the form:

and corresponds somehow to a conditional statement:

The above conditional statement (without orif list) selects for execution one of two sequences of statements, depending on the truth value of the boolean expression:

which is always evaluated till the end. For the execution of the conditional statement with orif list the specified conditons wb1,...,wbk are evaluated in succession, until the first one evaluates to true. Then the rest of the sequence wb1,...,wbk is abandoned and "then part" is executed. If none of the conditions wb1,...,wbk evaluates to true "else part" is executed (if any).

Conditional statements with orif list facilitate to program those conditions, which evaluation to the end may raise a run-time error.

Example:

The execution of the statement:

where the value of i is greater than n, and A is an array with upper bound n, will raise the run-time error. Then the user can write:

what allows to avoid this run-time error and probably agrees with his intension.

Conditional statement with andif list has the form:

For the execution of this kind of statements, the conditions wb1,...,wbk are evaluated in succession, until the first one evaluates to false; then "else part" (if any) is executed. Otherwise "then part" is executed.

Iteration statement in LOGLAN-82 has the form:

An iteration statement specifies repeated execution of the sequence of statements and terminates with the execution of the simple statement exit

Example:

If two iteration statements are nested, then double exit in the inner one terminates both of them.

Example:

In the example above simultaneous assignment statements are illustrated (e.g. r,x:=0) and comments, which begin with a left parenthesis immediately followed by an asterisk and end with an asterisk immediately followed by a right parenthesis.

Triple exit terminates three nested iteration statements, four exit terminates four nested iteration statements etc.

The iteration statement with while condition:

is equivalent to:

The iteration statements with controlled variables (for statements) have the forms:

or

The type of the controlled variable j must be discrete. The value of this variable in the case of the for statement with to is increased, and in the case of the for statement with downto is decreased. The discrete range begins with the value of wa1 and changes with the step equal to the value of wa2. The execution of the for statement with to terminates when the value of j for the first time becomes greater than the value of wa3 (with downto when the value of j for the first time becomes less than the value of wa3). After the for statement termination the value of its controlled variable is determined and equal to the first value exceeding the specified discrete range.

The values of expressions wa1, wa2 and wa3 are evaluated once, upon entry to the iteration statement. Default value of wa2 is equal 1 (when the keyword step and expression wa2 are omitted).

For or while statements may be combined with exit statement.

Example:

The above iteration statement terminates either for the least j, 1<=j<=n, such that x=A(j) or for j=n+1 when x=/=A(j), j=1,...,n.

To enhance the user's comfort, the simple statement repeat is provided. It may appear in an iteration statement and causes the current iteration to be finished and the next one to be continued (something like jump to CONTINUE in Fortran's DO statements).

Example:

Just as exit, repeat may appear in for statement or while statement. Then the next iteration begins with either the evaluation of a new value of the controlled variable (for statement) or with the evaluation of the condition (while statement).

Case statement in LOGLAN-82 has the form:

where WA is an expression , L1,...,Lk are constants and I1,..., Ik,I are sequences of statements.

A case statement selects for execution a sequence of statements Ij, 1<=j<=k, where the value of WA equals Lj. The choice otherwise covers all values (possibly none) not given in the previous choices. The execution of a case statement chooses one and only one alternative (since the choices are to be exhaustive and mutually exclusive).




Last update 02/07/95
Comments, suggestions and critiques are welcome to : [email protected]