tracker issue : CF-3037178

select a category, or use search below
(searches all categories and all time range)
Title:

Bug 74802:Allow for (item in collection) syntax to work for *all* types of collection

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Sean Corfield / Sean Corfield (Sean Corfield)

Created: 01/06/2009

Components: Language, CFSCRIPT

Versions: 9.0

Failure Type: Unspecified

Found In Build/Fixed In Build: 0000 /

Priority/Frequency: Normal / Unknown

Locale/System: English / Platforms All

Vote Count: 11

Problem:

Allow for (item in collection) syntax to work for *all* types of collection.

Currently you can use for (key in someStruct) to loop over a structure but you cannot loop over an array or query using a similar syntax.

For an array, you must do for (i = 1; i <= arrayLen(someArray); ++i) - but <cfloop> allows the simpler <cfloop index="element" array="#someArray#"> to iterate over elements. It would be great to say for (element in someArray) and have element take on each array element's value just like the <cfloop array=> syntax.

For a query, you must do for (i = 1; i <= someQry.recordCount; ++) and then someQry['col'][i] to access the elements. With <cfloop> you can simply iterate over the rows. It would be great to say for (row in someQry) and then row.col directly inside the loop.
Method:


Result:

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3037178

External Customer Info:
External Company:  
External Customer Name: Sean Corfield
External Customer Email: 479B4EDC43F3A88B992016B6
External Test Config: 01/06/2009

Attachments:

Comments:

+1 vote. Very good suggestion. A simple (to the outside user, anyhow ;-) enhancement which will positively impact a lot of coding.
Vote by External U.
24240 | November 10, 2011 07:10:33 PM GMT
This bug has been voted..
Vote by External U.
24241 | November 10, 2011 07:10:34 PM GMT
This bug has been voted..
Vote by External U.
24242 | November 10, 2011 07:10:35 PM GMT
This bug has been voted..
Vote by External U.
24243 | November 10, 2011 07:10:36 PM GMT
This bug has been voted..
Vote by External U.
24244 | November 10, 2011 07:10:37 PM GMT
This bug has been voted..
Vote by External U.
24245 | November 10, 2011 07:10:38 PM GMT
This is supported in tags with the new array loop... there's no reason it shouldn't be implemented in script as well.
Vote by External U.
24246 | November 10, 2011 07:10:39 PM GMT
This bug has been voted..
Vote by External U.
24247 | November 10, 2011 07:10:40 PM GMT
This bug has been voted..
Vote by External U.
24248 | November 10, 2011 07:10:41 PM GMT
+1 This is something I've tried to write code for a few time with CF8 since the new array loop was added, before remembering its not supported. :)
Vote by External U.
24249 | November 10, 2011 07:10:42 PM GMT
This bug has been voted..
Vote by External U.
24250 | November 10, 2011 07:10:43 PM GMT