while: block x block -> ()
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.
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 arise, when condBlock returns no value (Missing Parameter) or a non-boolean result (Type mismatch).
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.
> sq := [c];
> while(`#sq < 8', `sq := sq + transp(sq,2); write(sq)')
[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:
(occured while executing function "while")
See also: loop, loopn, if.