In this example, the code loops four times, displaying the
decreased by one for each iteration. This does not affect the value of
that is made before entering the loop.
<cfset j = 4>
<cfloop index = "LoopCount" from = "1" to = #j#>
<cfoutput>The loop index is #LoopCount#</cfoutput>.<br>
<cfset j = j - 1>
</cfloop>
The output of this loop is as follows:
The loop index is 1.
The loop index is 2.
The loop index is 3.
The loop index is 4.
As before, the value of
value of
, because its value is a copy of
to
In this example,
<cfloop index = "LoopCount"
from = "5"
to = "1"
step = "-1">
The loop index is <cfoutput>#LoopCount#</cfoutput>.<br>
</cfloop>
The output of this loop is as follows:
The loop index is 5.
The loop index is 4.
The loop index is 3.
The loop index is 2.
The loop index is 1.
234
Chapter 2: ColdFusion Tags
is decremented by one for each iteration, but this does not affect the
j
has the default value, 1. The code decrements the index:
step
index
that is made before the loop is entered.
j
value each time. The value of
, because it is a copy of
to
is
j
j