I don't know how CFLOOP works exactly.  I'd imagine it evaluates the values
of it's attributes when initially encountered, and then uses those values.
So if the length of the 'iterations' array changes, CFLOOP doesn't know that
it has a new stopping point.  CFSCRIPT's for loop, on the other hand,
definitely reevaluates the arrayLen(iterations) _expression_ every time
through the loop.

If my suspicions about CFLOOP are correct, then those two code blocks are
NOT equivalent, but these blocks are:

<cfscript>
count = arrayLen(iterations);
for(i=1;i LTE count; i = i + 1)
{
   thisIteration = getIteration(iterations[i]);
   if(this.error)return thisRoute;
   arrayAppend(thisRoute.iterations, thisIteration);
}
</cfscript>

<cfset count = arrayLen(iterations) />
<cfloop from="1" to="#count#" index="i">
  <cfset thisIteration = getIteration(iterations[i])>
  <cfif this.error><cfreturn thisRoute></cfif>
  <cfset arrayAppend(thisRoute.iterations, thisIteration)>
</cfloop>

Cheers,
barneyb

> -----Original Message-----
> From: Adrocknaphobia [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 03, 2004 11:27 AM
> To: CF-Talk
> Subject: <cfscript> != <cftags>
>
> I've run into this issue a few times in the past. Whereas
> cfscript code wasnt executing as expected, but when converted
> to tags it works properly. Here is my latest issue. I figured
> I'd post it here to see if anyone knew why its not working.
>
> the iterations array has a length of 2.
>
> <cfscript>
> for(i=1;i LTE arrayLen(iterations); i = i + 1)
> {
>    thisIteration = getIteration(iterations[i]);
>    if(this.error)return thisRoute;
>    arrayAppend(thisRoute.iterations, thisIteration);
> }
> </cfscript>
>
> The above script creates a new iteration, but only with 1 element.
>
> <cfloop from="1" to="#arrayLen(iterations)#" index="i">
>   <cfset thisIteration = getIteration(iterations[i])>
>   <cfif this.error><cfreturn thisRoute></cfif>
>   <cfset arrayAppend(thisRoute.iterations, thisIteration)>
> </cfloop>
>
> The tag based approach, which is an exact conversion creates
> a new array with 2 elements as expected.
>
> So anyone have any idea why the tag based approach works but
> the script version doesn't?
>
>
> [Adam Wayne Lehman]
>
> ------------------------------------------------------------
> If you don't fake the funk, the funk will fake you.
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to