ColdFusion Snippet Stumper
- October 16, 2009 10:37 AM
- ColdFusion
- Comments (4)
I ran across this bit of CF code in a project that I'm working on upgrading, and I was so completely confused by the it that I thought I might throw it up here to see what people think of it.
...
<cfloop query="GetTimesheetData">
<cfset additionalNumber = additionalNumber />
<cfloop from="#startDate#" to="#endDate#" index="i">
<cfset temp_list="hours_#projectCode#_#taskCode#_#positionCode#_#i#" />
<cfset temp_projectCode = ListGetAt(temp_list,2,"_") />
<cfset temp_taskCode = ListGetAt(temp_list,3,"_") />
<cfset temp_positionCode = ListGetAt(temp_list,4,"_") />
<cfset temp_WorkDate = ListGetAt(temp_list,5,"_") />
<cfif temp_WorkDate eq i>
<cfif temp_projectCode eq projectCode>
<cfif temp_taskCode eq taskCode>
<cfif temp_positionCode eq positionCode>
<!--- Do stuff with the data --->
...
</cfif>
</cfif>
</cfif>
</cfif>
</cfloop>
</cfloop>
...
<cfloop query="GetTimesheetData">
<cfset additionalNumber = additionalNumber />
<cfloop from="#startDate#" to="#endDate#" index="i">
<cfset temp_list="hours_#projectCode#_#taskCode#_#positionCode#_#i#" />
<cfset temp_projectCode = ListGetAt(temp_list,2,"_") />
<cfset temp_taskCode = ListGetAt(temp_list,3,"_") />
<cfset temp_positionCode = ListGetAt(temp_list,4,"_") />
<cfset temp_WorkDate = ListGetAt(temp_list,5,"_") />
<cfif temp_WorkDate eq i>
<cfif temp_projectCode eq projectCode>
<cfif temp_taskCode eq taskCode>
<cfif temp_positionCode eq positionCode>
<!--- Do stuff with the data --->
...
</cfif>
</cfif>
</cfif>
</cfif>
</cfloop>
</cfloop>
...
I personally cannot think of anything that the code inside the <cfloop> actually accomplishes. Am I missing something?
Comments
The statement like <cfif temp_positionCode eq positionCode> is always true because temp_positionCode is always going to be equal to positionCode since that is what it is set to with <cfset temp_positionCode = ListGetAt(temp_list,4,"_") />.
To confirm all statements are always true you could output something like #temp_WorkDate eq i# and #temp_projectCode eq projectCode# for each row, for each condition.