do...until
Loops through a block of PSL code until an expression is evaluated as TRUE
Syntax
do{
{ BLOCK }
} until ( expression );
Parameters
Parameter | Definition |
---|---|
BLOCK | one or more PSL statements that are repeatedly executed |
expression | PSL statement where the evaluation returns either TRUE or |
Description
The PSL do...until
loop behaves similarly to the C do...while
loop construct in that it tests the termination condition at the end of the loop after making each pass through the body of the loop. Therefore, the body is always executed at least once. At first pass, the BLOCK of statements is executed, then expression is evaluated. If expression is FALSE, the BLOCK of statements is executed again. Iteration repeats until expression is TRUE.
The following example demonstrates the PSL do...until
loop:
i = 10;
do {
printf(" %d seconds to go\n",i);
i--;
sleep(1);
} until ( i == 0);
This example produces the following output:
10 seconds to go
9 seconds to go
8 seconds to go
7 seconds to go
6 seconds to go
5 seconds to go
4 seconds to go
3 seconds to go
2 seconds to go
1 seconds to go
Comments
Log in or register to comment.