MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 136

Developing coldfusion mx applications
Table of Contents

Advertisement

if(Find("key",strings[indx],1)) {
WriteOutput("Found key at " & indx & ".<br>");
break;
}
else if (indx IS ArrayLen(strings)) {
WriteOutput("Exited at " & indx & ".<br>");
break;
}
}
</cfscript>
This example shows one important issue that you must remember when creating loops: you must
always ensure that the loop ends. If this example lacked the
"key" in the array, ColdFusion would loop forever or until a system error occurred; you would
have to stop the server to end the loop.
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
statement does the following:
while
Evaluates the expression.
1
If the expression is True, it does the following:
2
Executes the statement, which can be a single semicolon-terminated statement or a
a
statement block in curly braces.
Returns to step 1.
b
If the expression is False, processing continues with the next statement.
The following example uses a
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
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);
136
Chapter 6: Extending ColdFusion Pages with CFML Scripting
loop to populate a 10-element array with multiples of five.
while
statement, and there was no
else if
expression is False and you
while

Advertisement

Table of Contents
loading
Need help?

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents