Hey Rob

I think that variables referenced within the loop conditional are
considered local

I've seen this is some languages -- Fortran, Forth, _javascript_? Java?

the inner just opens a new local scope

I wonder what happens if you declare the var within the conditional.

If you want to get to the outer variable:

1) Use a different variable
2) set another variable, say outeri = i; before executing an inner

I think it is a feature, not a bug.

If that is what is supposed to happen, then it might make sense to use
the same variable (for clarity) within a deeply nested set of
conditionals -- instead of i,j,k,l,m....

One look at the code would tell you that the redundant variable name
applies to this level only -- not an inner or outer level.

That's my SWAG!

Dick

As it is,
On Aug 17, 2004, at 2:40 PM, Rob wrote:

> This may have been discussed before...
>
>  I received some code that has an outer loop and an inner loop that use
>  the same variable index name (which is horrid practice, but regardless
>  it sparked my curiosity).
>
>  Running this
>  #1
>  <cfscript>
>  for(i=0; i lte 10; i=i+1)
>  {
>  for(i=0; i lte 10; i=i+1)
>  {
>  writeoutput(i & "<br />");
>  }
>  }
>  </cfscript>
>
>  loops to 10 as I would expect, but this (which is like the block I
> got)
>  #2
>  <cfloop from="0" to="10" index="i">
>  <cfloop from="0" to="10" index="i">
>  <cfoutput>
>  #i#<br />
>  </cfoutput>
>  </cfloop>
>  </cfloop>
>
>  loops to 10 10 times (which happens to be the proper logic for the
>  application).
>
>  I am pretty sure it has to do with scoping, but in example #2 how
>  would you get to the outer loops version of i? caller.i is a no-go.
>
>  And Is this a bug or a feature?
>
>  (P.S. I am rewriting the problem block so it wont be an issue, I am
>  just curious)
>  --
>  ~The cfml plug-in for eclipse~
>  http://cfeclipse.tigris.org
>  ~open source xslt IDE~
>  http://treebeard.sourceforge.net
>  ~open source XML database~
>  http://ashpool.sourceforge.net
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to