Consider this list:
<cfset foo = "one,two,three,four" />
Attribute | Required | Default | Description |
---|---|---|---|
list | true | A list object. The variable must be evaluated (wrapped with ##) | |
index | true | The current element of the list. |
<cfoutput>
<cfloop list="#foo#" index="x">
<li>#x#</li>
</cfloop>
</cfoutput>
This will also have a line break between each line of HTML.
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
<cfscript>
for (x = 1; x LTE listLen(foo); x = x + 1) {
writeOutput("<li>" & listGetAt(foo, x) & "</li>");
}
</cfscript>
<cfscript>
for (x = 1; x <= listLen(foo); x++) {
writeOutput("<li>" & listGetAt(foo, x) & "</li>");
}
</cfscript>
<cfscript>
for (x in foo) {
writeOutput("<li>" & x & "</li>");
}
</cfscript>
The cfscript function
cfloop
has no support forlist
.
Notice that the cfscript output is all on one line.
<li>one</li><li>two</li><li>three</li><li>four</li>