22.08.2013 Views

ColdFusion Developer's Guide

ColdFusion Developer's Guide

ColdFusion Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta<br />

a. Executes the statement, which can be a single semicolon-terminated statement or a<br />

statement block in curly braces.<br />

b. Returns to step 1.<br />

If the expression is False, processing continues with the next statement.<br />

The following example uses a while loop to populate a 10-element array with multiples of<br />

five.<br />

a = ArrayNew(1);<br />

loop = 1;<br />

while (loop LE 10) {<br />

a[loop] = loop * 5;<br />

loop = loop + 1;<br />

}<br />

As with other loops, you must make sure that at some point the while expression is False and<br />

you must be careful to check your index arithmetic.<br />

Using do-while loops<br />

The do-while loop is like a while loop, except that it tests the loop condition after executing<br />

the loop statement block. The do-while loop has the following format:<br />

do statement while (expression);<br />

The do while statement does the following:<br />

1. Executes the statement, which can be a single semicolon-terminated statement or a<br />

statement block in curly braces.<br />

2. Evaluates the expression.<br />

3. If the expression is true, it returns to step 1.<br />

If the expression is False, processing continues with the next statement.<br />

The following example, like the while loop example, populates a 10-element array with<br />

multiples of 5:<br />

a = ArrayNew(1);<br />

loop = 1;<br />

do {<br />

a[loop] = loop * 5;<br />

loop = loop + 1;<br />

}<br />

while (loop LE 10);<br />

Because the loop index increment follows the array value assignment, the example initializes<br />

the loop variable to 1 and tests to make sure that it is less than or equal to 10.<br />

Using CFScript statements 155

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!