Creating a simple index loop in ColdFusion using the CFLOOP tag

Readability

Creating a simple index loop in ColdFusion using the CFLOOP tag

The fol­low­ing exam­ple shows how you can cre­ate a sim­ple index loop in Cold­Fu­sion using the <CFLOOP> tag and set­ting the index, from and to attributes.

 
    counter == #counter#

The pre­ced­ing code pro­duces the fol­low­ing output:

counter == 1
counter == 2
counter == 3
counter == 4
counter == 5

You can also do index loops within a <CFSCRIPT> tag, as seen in the fol­low­ing example:


counter = 1;
for (counter=1; counter LTE 5; counter=counter+1) {
	writeOutput("counter == " & counter & "
"); }

The following example shows how you can create a simple index loop in ColdFusion using the <CFLOOP> tag and setting the index, from and to attributes.

<cfloop index="counter" from="1" to="5"> 
    <cfoutput>counter == #counter#<br/></cfoutput> 
</cfloop>

The preceding code produces the following output:

counter == 1
counter == 2
counter == 3
counter == 4
counter == 5

You can also do index loops within a <CFSCRIPT> tag, as seen in the following example:

<cfscript>
counter = 1;
for (counter=1; counter LTE 5; counter=counter+1) {
	writeOutput("counter == " & counter & "<br/>");
}
</cfscript>

Leave a Reply

Your email address will not be published.