User Guide

Table Of Contents
Using CFScript statements 133
The example also shows two issues with index arithmetic: in this form of loop you must make
sure to initialize the index, and you must keep track of where the index is incremented. In this
case, because the index is incremented at the top of the loop, you must initialize it to 0 so it
becomes 1 in the first loop.
Using while loops
The while loop has the following format:
while (expression) statement
The while statement does the following:
1.
Evaluates the expression.
2.
If the expression is True, it does the following:
a
Executes the statement, which can be a single semicolon-terminated statement or a
statement block in curly braces.
b
Returns to step 1.
If the expression is False, processing continues with the next statement.
The following example uses a
while loop to populate a 10-element array with multiples of five.
a = ArrayNew(1);
loop = 1;
while (loop LE 10) {
a[loop] = loop * 5;
loop = loop + 1;
}
As with other loops, you must make sure that at some point the while expression is False and you
must be careful to check your index arithmetic.
Using do-while loops
The do-while loop is like a while loop, except that it tests the loop condition after executing the
loop statement block. The do-while loop has the following format:
do statement while (expression);
The do while statement does the following:
1.
Executes the statement, which can be a single semicolon-terminated statement or a statement
block in curly braces.
2.
Evaluates the expression.
3.
If the expression is true, it returns to step 1.
If the expression is False, processing continues with the next statement.