tracker issue : CF-3037367

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

Bug 75191:(Watson Migration Closure)adding two reserved variables currentRow and recordCount to cfloop array

| View in Tracker

Status/Resolution/Reason: Closed/Deferred/

Reporter/Name(from Bugbase): Nuri Cevik / Nuri Cevik (Nuri Cevik)

Created: 01/23/2009

Components: Language, Datastructure

Versions: 9.0

Failure Type: Unspecified

Found In Build/Fixed In Build: 0000 /

Priority/Frequency: Normal / Unknown

Locale/System: English / Platforms All

Vote Count: 2

Problem:

adding two reserved variables currentRow and recordCount to cfloop array

You can loop with array and you need to know the current row you have two options

1	use classic looping
	...
		<cfloop from="1" to="#ArrayLen(myArray)#" index=i>
			...
			<cfif BitAnd(i,1)> class="myDarkRow"<cfelse> class="myLightRow"</cfif>
			...
			#myArray[i]#
			...
		</cfloop>
	...
2	Array parameter on cfloop introduced on cf8
	...
		<cfset row = 0 />
		<cfloop array="#myArray#" index="myRow">
			<cfset row=row+1>
			...
			<cfif BitAnd(i,1)> class="myDarkRow"<cfelse> class="myLightRow"</cfif>
			...
			#myRow#
			...
		</cfloop	
	It would be very efficient to have currentRow and recordCount on cfloop with array. So the code
	can be used as
		
		<cfloop array="#myArray#" index="myRow">
			...
			<cfif BitAnd(myRow.currentRow,1)> class="myDarkRow"<cfelse> class="myLightRow"</cfif>
			...
			#myRow#
			...
		</cfloop>
		
	We do not have to add counter on the new method and will bring consistency with query looping 
	and will help developers to use interchangeable code.


Method:


Result:

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

Watson Bug ID:	3037367

External Customer Info:
External Company:  
External Customer Name: Nuri Cevik
External Customer Email: 2DB6356443A04FCB99201549
External Test Config: 01/23/2009

Attachments:

Comments:

+1 vote, but only for the concept, not the suggested implementation. I think a better approach would be to have something like this: [code] <cfloop array="#a#" index="theValue" counter="thePositionInTheArray"> [/code] Where theValue is a variable holding the array element value, and counter is holding which array index point the value is at. It would have been better if Adobe had not used "index" the way they have (which is incorrect usage, IMO), because then one could do this: [code] <cfloop array="#a#" element="theValue" index="thePositionInTheArray"> [/code] Which uses more correct nomenclature for arrays: it's array[index] = element, not array[something] = index. Reed's right: there's no need for the recordCount (sic) here, aarayLen() is fine. -- Adam
Vote by External U.
24110 | November 10, 2011 07:14:22 PM GMT
Vote -1 I'm not sure that I agree with the concept, but I definitely don't agree with the suggested implementation of having the reserved variables. What scope would they be in? Would having such variables created interfere with an inner CFLOOP QUERY= that doesn't scope its recordCount and currentRow to the query scope? I know that scoping is always best, but not everyone - especially those who learned CF from the examples in the earlier CF "bibles" - does so, and it's important to not break existing code. What happens when there is an inner CFLOOP over a second array? What's the difference between recordCount (shouldn't that be "rowCount" since this is an array, not query resultset?) and arrayLen()?
Vote by External U.
24111 | November 10, 2011 07:14:24 PM GMT