View comments | RSS feed

cfloop: looping over a list or file

Description

Looping over a list steps through elements contained in any of these entities:

Syntax

<cfloop 
  index = "index_name"
  list = "list_items"
  delimiters = "item_delimiter">
  ...
</cfloop>

See also

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

Attributes

Attribute Req/Opt Default Description
index
Required

In a list loop, the variable to receive next list element.
list
Required

A list, variable, or file name; contains a list
delimiters
Optional

Character(s) that separates items in list

Example

This loop displays four names:

<cfloop index = "ListElement" 
  list = "John,Paul,George,Ringo"> 
    <cfoutput>#ListElement#</cfoutput><br> 
</cfloop>

You can put more than one character in the delimiters attribute, in any order. For example, this loop processes commas, colons, and slashes as list delimiters:

<cfloop index = "ListElement" 
  list = "John/Paul,George::Ringo" 
  delimiters = ",:/"> 
    <cfoutput>#ListElement#</cfoutput><br> 
</cfloop>

ColdFusion skips the second and subsequent consecutive delimiters between list elements. Thus, in the example, the two colons between "George" and "Ringo" are processed as one delimiter.

To loop over each line of a file, use the tag this way:

<cfloop list="#theFile#" 
  index="curLine" 
  delimiters="#chr(10)##chr(13)#"> 
  ...
</cfloop>

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

Version 6

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

Comments


jrunrandy said on May 26, 2005 at 6:05 PM :
The filename functionality never existed but somehow it was added to the CFMX documentation. Also, it has persisted into the 6.1 and CFMX 7 docs.

I have added doc bug 60239 to track this issue.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt176.htm