<CFLOOP INDEX="index_name"
    LIST="list_items"
    DELIMITERS="item_delimiter">
</CFLOOP>

Looping over a list offers the option of walking through elements contained within a variable or value returned from an expression. In a list loop, the INDEX attribute specifies the name of a variable to receive the next element of the list, and the LIST attribute holds a list or a variable containing a list.

INDEX

Required. Defines the parameter that is the index value. The index value will be set to the FROM value and then incremented by 1 (or the STEP value) until it equals the TO value.

LIST

Required. The list items in the loop, provided directly or with a variable.

DELIMITERS

Optional. Specifies the delimiter characters used to separate items in the LIST.

Example

This loop will display the names of each of the Beatles:

<CFLOOP INDEX="ListElement" 
    LIST="John,Paul,George,Ringo"> 
        <CFOUTPUT>#ListElement#</CFOUTPUT><BR> 
</CFLOOP>

Although CFLOOP expects elements in the list to be separated by commas by default, you are free to specify your own element boundaries in the DELIMITER attribute. Here's the same loop as before, only this time CFLOOP will treat commas, colons, or slashes as list element delimiters:

<CFLOOP INDEX="ListElement" 
    LIST="John/Paul,George::Ringo" 
    DELIMITERS=",:/"> 
        <CFOUTPUT>#ListElement#</CFOUTPUT><BR> 
</CFLOOP>

Delimiters need not be specified in any particular order. Note that consecutive delimiters are treated as a single delimiter; thus the two colons in the previous example are treated as a single delimiter between "George" and "Ringo."