ColdFusion Query Loop Behavior Change in CF2016

January 9, 2022    

One way to iterate over a query in ColdFusion is to use for...in syntax in script context:

for ( local.row in local.queryData ) {
writeOutput( "#local.queryData.Name# is a #local.queryData.Title#<br/>" );
}

Here's the example on TryCF so you can change engines and see different behaviors.

In this example, local.row is struct-ish and represents the query row as a key-value pair. That's the data I want to be using.

Did you spot the bug in the example? I used local.queryData instead of local.row. I really shouldn't have done that, but at some point someone else has done this by mistake as well.

In CF11 and CF10 (and possibly prior versions), you'd get the same output for each iteration of the loop. In CF2016 and forward, you'd get the output that's appropriate for each row.