Is it necessary to var scope loop variables in CFScript?

Posted by Mel on Stack Overflow See other posts from Stack Overflow or by Mel
Published on 2011-01-06T04:00:39Z Indexed on 2011/01/06 4:53 UTC
Read the original article Hit count: 218

Filed under:
|

When using CFML and CF9 I usually var scope my loop variables; in this case local.i, for example:

<cfloop list="#this.list#" index="local.i">
  <cfif Len(local.i) GT 10>
    // do something
  </cfif>
</cfloop>

I recently started converting some stuff into CFScript, and (to my disappointment I found out that there is no way to loop over a list in CFScript) I'm wondering if I should still var scope my loop variables, and how:

for (i = 1; LTE ListLen(this.list); i = i + 1 ) {
  if (Len(ListGetAt(this.list, i) GT 10)) {
    // do something
  }
}

Should I be doing local.i = 1 and local.i = local.i + 1 istead of the sample code in my example? Is it necessary?

EDIT: I should also ask if the CFScript form of my CFML loop is correct; I ask because I just noticed that my CFML loop uses a , (comma and space) for the delimiter argument, which seems non-existence in the CFScript version of the loop.

© Stack Overflow or respective owner

Related posts about coldfusion

Related posts about coldfusion-9