Control flow actions
Control flow actions let you change the order in which action lines are executed.
There are two sets of control flow actions:
- conditional actions
- loops
Conditional actions allow you to decide, based on an expression, which actions lines to execute next. The main conditional action is if, followed possibly by else and always by end if. Here is an example:
if #n < 0
report n is negative
else
report n is not negative
end if
If the Boolean expression in the argument of the if action evaluates to true, the lines directly below it are executed until the next else or end if, whichever comes first. If the expression is false, those lines are skipped, but if there is an else the lines after the else up to the end if are executed.
Loops allow you to repeat a sequence of actions until a condition is false. The following example executes the action verify item with increasing values of n until n reaches 10.
while #n < 10
verify item #n
set variable n #n+1
end while
This can also be written with an until and repeat action pair, as follows:
repeat
verify item #n
set variable n #n+1
until #n>=10