<CFLOOP CONDITION="expression">

A conditional loop iterates over a set of instructions while a given condition is TRUE. To use this type of loop correctly, the instructions must change the condition every time the loop iterates until the condition evaluates as FALSE. Conditional loops are commonly known as WHILE loops, as in "loop WHILE this condition is true."

CONDITION

Required. Sets the condition that controls the loop. The loop will repeat as long as the condition evaluates as TRUE. When the condition is FALSE, the loop stops.

Example

The following example increments the parameter "CountVar" from 1 to 5. The results look exactly like the Index loop example.

<!--- Set the variable CountVar to 0 ---> 
<CFSET CountVar=0> 
<!--- Loop until CountVar = 5 ---> 
<CFLOOP CONDITION="CountVar LESS THAN OR EQUAL TO 5"> 
    <CFSET CountVar=CountVar + 1> 
    The loop index is <CFOUTPUT>#CountVar#</CFOUTPUT>.<BR> 
</CFLOOP>

The result of this loop in a browser would look something like:

The loop index is 1. 
The loop index is 2. 
The loop index is 3. 
The loop index is 4. 
The loop index is 5.