User Guide
Chapter 1: ColdFusion Tags 129
CFLOOP
Looping is a very powerful programming technique that lets you repeat a set of
instructions or display output over and over until one or more conditions are met.
CFLOOP supports five different types of loops:
• Index Loops
• Conditional Loops
• Looping over a Query
• Looping over a List
• Looping over a COM Collection or Structure
The type of loop is determined by the attributes of the CFLOOP tag.
Index Loops
An index loop repeats for a number of times determined by a range of numeric values.
Index loops are commonly known as FOR loops, as in "loop FOR this range of values. "
Syntax <CFLOOP INDEX="parameter_name"
FROM="beginning_value"
TO="ending_value"
STEP="increment">
...
HTML or CFML code to execute
...
</CFLOOP>
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.
FROM
Required. The beginning value of the index.
TO
Required. The ending value of the index.
STEP
Optional. Default is 1. Sets the value by which the loop INDEX value is
incremented each time the loop is processed.
Examples In this example, the INDEX variable is incremented for each iteration of the loop. The
following code loops five times, displaying the INDEX value of the loop each time:
<CFLOOP INDEX="LoopCount"