[Contents] · [Home] · [Mail]

SALIERI Language - loop

loop: stmnt_block x expr_block x stmnt_block x stmnt_block -> ()

Call syntax:
loop(initBlock, condBlock, iterBlock, bodyBlock)

loop is the most general loop function in SALIERI. Before entering the loop, initBlock is executed once (this should be used to initialize counters or other data-structures which are later manipulated in the body or iterator block of the loop). Then, in each iteration of the loop, first condBlock is evaluated. If it returns TRUE, the loop body bodyBlock and then iterBlock is executed (the latter should contain statements to increase / descrease counters or to manipulate other data structures which are used to control the loop). If condBlock returns FALSE, bodyBlock and iterBlock are not executed and the loop-statement is terminated. For the condBlock parameter, 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 loop does not accept a boolean value here.

When the number of loop-executions is known before entering the loop-statement, the control function loopn can be used to improve performance.

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

> MyFairLady := LIST("Es gruent", "so gruen", "wenn Spaniens", "Blueten bluehn")
> Faust := LIST("Von Zeit", "zu Zeit", "seh ich", "den Alten gern")
> loop(`a:=1', `a<=5', `a:=a+1', `write(MyFairLady@a); write(Faust@a)')
Es gruent
Von Zeit
so gruen
zu Zeit
wenn Spaniens
seh ich
Blueten bluehn
den Alten gern
> loop(`a:=1', `', `a:=a+1', `write(MyFairLady@a); write(Faust@a)')
Error in command-line:
Type mismatch
(occured while executing function "loop")

See also: while, loopn, if.

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