Thursday, July 23, 2009

Looping in ColdFusion

I really wish you could loop an array, query and struct in a consistent manner in ColdFusion. In truth, you're just iterating over a collection of data. Why does it need to be so different? For example, here's looping over a collection of Users and retrieving a single User record.

<cfloop array="#users#" index="user">


<cfloop collection="#users#" item="i">
<cfset user = users[i] />

<cfloop query="users">
<!--- convert the row into a struct in order to access all the user's data in a single collection --->
<cfset user = {} />
<cfloop list="#users.columnList#" index="i">
<cfset user[i] = users[i][currentRow] />

I really wish I could do...

<cfloop collection="#users#" index="user">


<cfloop query="#users#" index="user">


... but that might make too much sense.

Seriously, someone just needs to take all the nice parts of ColdFusion and re-write the damn language. It would make me so much happier. Also, don't get me started on the lack of #'s in cfloop query.