Tags · Functions · Objects
Lucee Tag Reference
Choose a tag:

Tag <CFLOOP>

Looping is a very powerful programming technique that lets you repeat a set of instructions or display output repeatedly until one or more conditions are met. cfloop supports five types of loops.

Body

This tag must have a body.

Example

	<cfloop
		[array="array"]
		[characters="number"]
		[charset="string"]
		[collection="any"]
		[condition="string"]
		[delimiters="string"]
		[endline="number"]
		[endrow="number"]
		[file="string"]
		[from="number"]
		[group="string"]
		[groupcasesensitive="boolean"]
		[index="string"]
		[item="string"]
		[label="string"]
		[list="string"]
		[maxrows="number"]
		[query="object"]
		[startline="number"]
		[startrow="number"]
		[step="number"]
		[struct="struct"]
		[times="numeric"]
		[to="number"]>

	</cfloop>
This tag is also supported within cfscript
	<cfscript>
		loop
		[array="array"]
		[characters="number"]
		[charset="string"]
		[collection="any"]
		[condition="string"]
		[delimiters="string"]
		[endline="number"]
		[endrow="number"]
		[file="string"]
		[from="number"]
		[group="string"]
		[groupcasesensitive="boolean"]
		[index="string"]
		[item="string"]
		[label="string"]
		[list="string"]
		[maxrows="number"]
		[query="object"]
		[startline="number"]
		[startrow="number"]
		[step="number"]
		[struct="struct"]
		[times="numeric"]
		[to="number"] {

	}
	</cfscript>

Attributes

The attributes for this tag are fixed. Except for the following attributes no other attributes are allowed.
Name Type Required Description
array array No An array. 
characters number No The number of characters to read during each iteration of the loop from the file specified in the file attribute.
If the value of the characters attribute is more than the number of characters in the file,
Lucee uses the number of characters in the file. 
charset string No charset for read the file 
collection any No Collection to loop over 
condition string No Condition that controls the loop. 
delimiters string No Character(s) that separates items in list 
endline number No end line 
endrow number No Last row of query that is included in the loop. You cannot use this attribute together with the attribute maxRows. 
file string No file path 
from number No Beginning value of index. 
group string No Specifies the query column to use when you group sets of records together to send as an e-mail
message. For example, if you send a set of billing statements to customers, you might group on
"Customer_ID." The group attribute, which is case sensitive, eliminates adjacent duplicates when the
data is sorted by the specified field. See the Usage section for exceptions. 
groupcasesensitive boolean No Boolean indicating whether to group with regard to case or not. The default value is NO;
case is considered while grouping. If the query attribute specifies a query object that was generated
by a case-insensitive SQL query, set the groupCaseSensitive attribute to NO to keep the recordset
intact. 
index string No Index value. Lucee sets it to from value and increments or decrements by step value, until it equals to value. 
item string No Key for the collection 
label string No used to a address this loop from a "break" or "continue" statement (instead of the nearest one). 
list string No A list, variable, or file name; contains a list 
maxrows number No Specifies the maximum number of rows to display in the output section. You cannot use this attribute together with the attribute endrow. 
query any No Query that controls the loop. this can be a variable name or the query itself. 
startline number No start line 
startrow number No First row of query that is included in the loop. 
step number No Step by which to increment or decrement the index value. 
struct struct No struct to loop over 
times numeric No used for a simple loop that is looping n times 
to number No Ending value of index.