Re: [Flashcoders] Variable scope within for loops: reusing iterator variables

2008-03-24 Thread Meinte van't Kruis
besides, the compiler only warns you that you're about the overwrite the
variable, by
re-assigning it. In case of 2 loops(where the variable is only used within
the loop),
it doesn't have any real consequences.

On Mon, Mar 24, 2008 at 4:56 PM, Cory Petosky <[EMAIL PROTECTED]>
wrote:

> Jonathon:
>
> In any other language, the scope would be as you describe. AS3 doesn't
> have block-level scoping -- the most local scope is always the
> function. Declaring a variable anywhere but the first line of a
> function is a lie -- the VM declares all variables as the first set of
> operations after pushing the function call on the stack.
>
> On Mon, Mar 24, 2008 at 7:36 AM, Andrew Sinning <[EMAIL PROTECTED]>
> wrote:
> > You are correct Jonathan, but loop blocks are delimited by brackets, so
> >  the "for ( ... )" declaration is outside of the loop block.
> >
> >
> >  jonathan howe wrote:
> >  > I had always thought that the scope of variables declared in the
> >  > initialization part of the for loop were local to the loop block
> >
> >
> >
> > ___
> >  Flashcoders mailing list
> >  Flashcoders@chattyfig.figleaf.com
> >  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
>
>
>
> --
> Cory Petosky : Lead Developer : PUNY
> 1618 Central Ave NE Suite 130
> Minneapolis, MN 55413
> Office: 612.216.3924
> Mobile: 240.422.9652
> Fax: 612.605.9216
> http://www.punyentertainment.com
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
M.A. van't Kruis
http://www.malatze.nl/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Variable scope within for loops: reusing iterator variables

2008-03-24 Thread Cory Petosky
Jonathon:

In any other language, the scope would be as you describe. AS3 doesn't
have block-level scoping -- the most local scope is always the
function. Declaring a variable anywhere but the first line of a
function is a lie -- the VM declares all variables as the first set of
operations after pushing the function call on the stack.

On Mon, Mar 24, 2008 at 7:36 AM, Andrew Sinning <[EMAIL PROTECTED]> wrote:
> You are correct Jonathan, but loop blocks are delimited by brackets, so
>  the "for ( ... )" declaration is outside of the loop block.
>
>
>  jonathan howe wrote:
>  > I had always thought that the scope of variables declared in the
>  > initialization part of the for loop were local to the loop block
>
>
>
> ___
>  Flashcoders mailing list
>  Flashcoders@chattyfig.figleaf.com
>  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
Cory Petosky : Lead Developer : PUNY
1618 Central Ave NE Suite 130
Minneapolis, MN 55413
Office: 612.216.3924
Mobile: 240.422.9652
Fax: 612.605.9216
http://www.punyentertainment.com
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Variable scope within for loops: reusing iterator variables

2008-03-24 Thread Andrew Sinning
You are correct Jonathan, but loop blocks are delimited by brackets, so 
the "for ( ... )" declaration is outside of the loop block.


jonathan howe wrote:

I had always thought that the scope of variables declared in the
initialization part of the for loop were local to the loop block


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Variable scope within for loops: reusing iterator variables

2008-03-23 Thread Kerry Thompson
jonathan howe wrote:

> I was hoping someone could explain why I get "Warning: 3596: Duplicate
> variable definition." warnings when I reuse an iterator variable.
> Example:
> 
> for (var i:int = 0; i < someArray.length; i ++) {
>   // do something cool
> }
> 
> for (var i:int = 0; i < someOtherArray.length; i ++) {
>   // do something even cooler
> }

The first time you declare the var i, it is in scope for the rest of the
function, not the loop. Think of it this way:

function someFunc():void
{
   .
   .
   .
   var i:int;
   for (i = 0; i < someArray.length; i ++) {
   // do something cool
   }

   for (i = 0; i < someOtherArray.length; i ++) {
  // do something even cooler
   }
}

Make sense?

Cordially,

Kerry Thompson


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Variable scope within for loops: reusing iterator variables

2008-03-23 Thread jonathan howe
I was hoping someone could explain why I get "Warning: 3596: Duplicate
variable definition." warnings when I reuse an iterator variable.
Example:

for (var i:int = 0; i < someArray.length; i ++) {
  // do something cool
}

for (var i:int = 0; i < someOtherArray.length; i ++) {
  // do something even cooler
}

I had always thought that the scope of variables declared in the
initialization part of the for loop were local to the loop block, not the
block containing the loop. So I guess that is not true... does this mean the
second time I use the loop I have to omit the declaration? Or is there a
keyword I can use to keep the instantiation local to the for block? Seems
like it would be clunky if I was cutting and pasting blocks of code in
different orders, I'd have to keep track of who was the first for loop of
any code block (an admittedly minor annoyance, since I don't have stacks and
stacks of loops, but still...)

Thanks in advance,
-jonathan



-- 
-jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders