View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfloop: conditional loop PreviousNext

cfloop: conditional loop

A conditional loop iterates over a set of instructions as long as a condition is True. To use this type of loop correctly, the instructions must change the condition every time the loop iterates, until the condition is False. Conditional loops are known as WHILE loops, as in, "loop WHILE this condition is true."

<cfloop 
condition = "expression">
...
</cfloop>

cfabort, cfbreak, cfexecute, cfexit, cfif, cflocation, cfswitch, cfthrow, cftry

Attribute

Req/Opt

Default

Description

condition

Required

 

Condition that controls the loop.

The following example increments CountVar from 1 to 5.

<!--- 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 output of this loop is as follows:

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. 

Contents > CFML Reference > ColdFusion Tags > cfloop: conditional loop PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


tzimmerman said on Apr 28, 2004 at 11:25 AM :
The <cfloop condition = "CountVar LESS THAN OR EQUAL TO 5"> is incorrect. It will print out values upto 6. The correct condition should be as follows:

<cfloop condition = "CountVar LT 5">

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p78.htm