[Contents] · [Home] · [Mail]

SALIERI Language - while

Type:
while: block x block -> ()

Call syntax:
while(condBlock, bodyBlock)

Description:
The control function while implements a conditional loop. In each iteration of the loop, first the condition block condBlock is evaluated; if the result is TRUE, the loop body bodyBlock is executed then. This is iterated until condBlock evaluates to FALSE.

For the condBlock parameters, any block can be used which is guaranteed to return a value of type boolean; therefore its execution may cause side-effects. However, to increase readability of SALIERI code, this should be avoided.

Attention!
Usually, condBlock will contain a boolean expression (condition). However, it has to be specified as a block (i.e., be enclosed in block-quotes), since if does not accept a boolean value here.

Error conditions:
Error conditions arise, when condBlock returns no value (Missing Parameter) or a non-boolean result (Type mismatch).

Attention!
In many instances, using the more general loop-function helps to avoid errors and increase readability of SALIERI code. When the number of loop-executions is known before entering the loop-statement, the control function loopn can be used to improve performance.

Example:
> sq := [c];
> while(`#sq < 8', `sq := sq + transp(sq,2); write(sq)')
[c1/4 d1/4]
[c1/4 d1/4 e1/4 f#1/4]
[c1/4 d1/4 e1/4 f#1/4 g#/4 a#/4 c2/4 d2/4]
> while(sq < 16, `sq := sq + sq; write(sq)')
Error in command-line:
Type mismatch
(occured while executing function "while")

See also: loop, loopn, if.


[Contents] · [Home] · [Mail]
© sic!systems, page frame designed by hh; this page has been automatically generated from the SALIERI Documentation Database.