The
statement does the following:
do while
Executes the statement, which can be a single semicolon-terminated statement or a statement
1
block in curly braces.
Evaluates the expression.
2
If the expression is true, it returns to step 1.
3
If the expression is False, processing continues with the next statement.
The following example, like the while loop example, populates a 10-element array with multiples
of 5:
a = ArrayNew(1);
loop = 1;
do {
a[loop] = loop * 5;
loop = loop + 1;
}
while (loop LE 10);
Because the loop index increment follows the array value assignment, the example initializes the
loop variable to 1 and tests to make sure that it is less than or equal to 10.
The following example generates the same results as the previous two examples, but it increments
the index before assigning the array value. As a result, it initializes the index to 0, and the end
condition tests that the index is less than 10.
a = ArrayNew(1);
loop = 0;
do {
loop = loop + 1;
a[loop] = loop * 5;
}
while (loop LT 10);
using for-in loops
The for-in loop loops over the elements in a ColdFusion structure. It has the following format:
for (variable in structure) statement
The variable can be any ColdFusion identifier; it holds each structure key name as ColdFusion
loops through the structure. The structure must be the name of an existing ColdFusion structure.
The statement can be a single semicolon terminated statement or a statement block in curly
braces.
The following example creates a structure with three elements. It then loops through the structure
and displays the name and value of each key. Although the curly braces are not required here, they
make it easier to determine the contents of the relatively long
you can make structured control flow, especially loops, clearer by using curly braces.
myStruct=StructNew();
myStruct.productName="kumquat";
mystruct.quality="fine";
myStruct.quantity=25;
for (keyName in myStruct) {
WriteOutput("myStruct." & Keyname & " has the value: " &
myStruct[keyName] &"<br>");
}
function. In general,
WriteOutput
Using CFScript statements
137
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers