Let's loop through a list using <cfloop>
and then compare it to looping through it using <cfscript>:
1. First, create a file named
looplist.cfm
in the<Railo Installation Directory>/webroot/Chapter_6
folder and create a list by adding the following code:<cfset myList = "Item One,Item Two,Item Three">
2. Now, let's loop through the list using
<cfloop>
by appending the following code:<cfloop list="#myList#" index="i"> <cfoutput>#i#<br></cfoutput> </cfloop>
3. This prints out the following output, as expected:
Item One Item Two Item Three
4. Let's replace the
<cfloop>
with the following lines of code:<cfscript> for(i = 1; i <= ListLen(myList); i+){ WriteOutput(ListGetAt(myList, i) & "<br>"); } </cfscript>
5. We get the same output, but of course, we seem to be doing it rather differently.