while ... do

The while ... do keywords run a statement repeatedly until the specified termination condition evaluates to zero. The system tests the terminating condition before each iteration of the loop, so a while loop executes zero or more times depending on the value of the termination expression.

The begin/end keywords enclose a group of statements that form the body of a while/do loop. You can use the begin/end keywords to run one or more statements conditionally. If you include more than one statement in the body of a while/do loop, you must surround the statements with the begin/end keywords. If you use only a single statement, you can omit the begin/end.

Note: Do not end conditions with a semicolon (;) – this terminating syntax is necessary for statements only.

Common use

The while/do function is often used to initialize arrays, add or remove characters from a string, and to loop through iterations of a repeating structure. For more in-depth examples, see the "Using While Do Loops In Extended Rules" white paper.

Syntax

while condition do

Example

integer i;

while i < 10 do
begin 
       i = i + 1;
       if (i = 8) then
          continue;
       if (i = 9) then
          break;
end 
//While "i" is less than ten, run the loop. If "i" is equal to or
//greater than ten, terminate the loop.