Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 123

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
The example also shows two issues with index arithmetic: in this form of loop you must make sure to initialize the
index, and keep track of where the index is incremented. In this case, because the index is incremented at the top of
the loop, 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
a
Executes the statement, which can be a single semicolon-terminated statement or a statement block in curly
brackets.
b
Returns to step 1.
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, make sure that at some point the
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
statement does the following:
dowhile
Executes the statement, which can be a single semicolon-terminated statement or a statement block in curly
1
brackets.
2
Evaluates the expression.
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);
loop to populate a 10-element array with multiples of five.
while
expression is False and be careful to check your index
while
Last updated 1/20/2012
118

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents