Chapter 3 The Application Description Language

3.15 Control Flow

The ADL provides a standard and predictable set of control structures, as shown in Figure 3.32:
Control Structures
if ( BoolExpression ) { . . . }

[ else if ( BoolExpression ) { . . . } ]

. . .

[ else { . . . } ]

for i in list { . . . }
for i in array { . . . }
while ( BoolExpression ) { . . . }
do { . . . } while ( BoolExpression );
cond {
( BoolExpression1 ) { ... }
[ ( BoolExpression2 ) { ... }]
[ ... ]
}
break;
continue;
return [ value ];
forward => [ selector @] object/handle;

There are three non-C++ control structures:

1. for i in list { . . . } iterates over the elements of the list and executes the code in the block repeatedly with the variable i assigned to each member of the list in turn. This usage requires that all list elements are of the same type (the declared type of the variable i) or that i be of type any.

2. for i in array { . . . } iterates over the state of the array when the for statement is first entered. For each such assigned element, i is assigned a list whose first member is the value of the array element, and whose second through n+INDEXES (not implemented) members are the values of the element's indices, where n is the number of array indices. The order in which the elements are visited is unpredictable.

3. cond, borrowed from LISP, guarantees that at most one of the code blocks within the cond block is executed, the first that is preceded by a TRUE boolean expression. A default can be specified using TRUE.

We discuss the forward statement in Section 3.21, "Method Definition" page 41.

Non-C++ Control Structures
list alist;

any value

for value in alist {

if (isInteger (value)) {

echo("Value is an integer\n");

{else {

echo("Value is not an integer\n");

}

}

integer anArray<string>;

list alist;

anArray["Steve"} = 43;

anArray["Lori"] = 42;

for alist in anArray{

echo("Age of"&at(2,alist)&"is"&at(1,alist)+"\n");

}

integer ival = 7;

cond{

(ival >= 2) {

echo("Integer greater than 2\n");

}

(ival >= 0 {

echo("Integer greater than or equal to 0

but less than 2\n");

}

(TRUE) {

echo("Integer is negative\n");

}

}


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker