|
Cfscript looping over lists |
I really like cfscript, but as with any skill I don't use it often in my current role (its not 'standard') so I find that my knowledge of it is on the wane.
I do develop extensively outside of a working environment, so I find myself deliberately writing cfscript code rather than 'normal' coldfusion. I think it is because it is more like javascript, actionScript or .Net, I like the script formatting.
So I find myself looping over a series of lists in a form action template, I thought I would experiment with the different ways of doing the loop, cfscript and non script. So I create a simple list.
Now loop over it in the traditional way.
2 <cfloop from="1" to="#listLen(variables.myList)#" index="L">
3 #ListGetAt(variables.myList, L)#<br/>
4 </cfloop>
5</cfoutput>
And now the cfscript way.
2 For (i=1;i LTE ListLen(variables.myList); i=i+1)
3 writeoutput(ListGetAt(variables.myList, i)&'<BR>');
4</cfscript>
Both code blocks give the same output, I much prefer the code style of the second block though.
for (i=1;i <= listLen(variables.myList); i++) {
}
myArray = listToArray( myList )
I really like where CF9 is going with CFScript, the idea that Ray Camden posts here (http://www.coldfusionjedi.com/index.cfm/2008/5/2/A...) is interesting, that CF9 will have full CFScript CFC functionality. Building CFC’s in CFScript would be an intriguing change, especially in the translation to and from Flex.