Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 124

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
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);
The following example loops through a query:
<cfquery ... name="myQuery">
... sql goes here...
</cfquery>
<cfscript>
if (myQuery.RecordCount gt 0) {
currRow=1;
do {
theValue=myQuery.myField[CurrRow];
currRow=currRow+1;
} while (currRow LTE myQuery.RecordCount);
}
</cfscript>
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 reference.
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 brackets are not required here, they make it easier to determine the
contents of the relatively long
loops, clearer by using curly brackets.
myStruct=StructNew();
myStruct.productName="kumquat";
mystruct.quality="fine";
myStruct.quantity=25;
for (keyName in myStruct) {
WriteOutput("myStruct." & Keyname & " has the value: " &
myStruct[keyName] &"<br>");
}
Note: Unlike the
tag, CFScript for-in loops do not provide built-in support for looping over queries and lists.
cfloop
Using continue and break statements
The continue and break statements enable you to control the processing inside loops:
• The
statement tells ColdFusion to skip to the beginning of the next loop iteration.
continue
function. In general, you can make structured control flow, especially
WriteOutput
Last updated 1/20/2012
119

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents