Looping allows you to repeat specific blocks
of code (both HTML and CFML) within your CFML templates. ColdFusion
supports a variety of looping constructs with the
<CFLOOP> tag, including index
for) loops, conditional
while) loops, collection loops, list loops, and
query loops. For now, we are just going to cover basic index and
conditional loops. Query loops are covered in Chapter 4, while collection and list loops are covered
in Chapter 6.
Also known as a
an index loop repeats a number of times specified as a range of
increment"> HTML and CFML... </CFLOOP>
INDEX attribute of
the loop specifies a variable name to hold the value corresponding to
the current iteration of the loop. The
attribute initializes the starting value for the loop. The
TO attribute refers to the value at which
iteration should stop.
STEP specifies the
increment value for each iteration of the loop.
STEP may be either a positive or a negative
number. Here is an example that uses an index loop to output all the
10, with each number on its own
<H2>Calling the loop...</H2> <CFLOOP INDEX="i" FROM="10" TO="100" STEP="10"> <CFOUTPUT> #i#<BR> </CFOUTPUT> </CFLOOP> <H2>We are now outside of the loop</H2>
INDEX is set to
we want to begin the count at
10, we assign that
value to the
FROM attribute. The
TO attribute is set to
100 because ...