If you want to make the scope "local", you can do it in a function or in a
class.

Function doLoop1():void{
  for ( i = 0; i < 10; i++) {
       trace('1st loop: ' + i);
 }
}

Function doLoop2():void{
  for ( i = 0; i < 10; i++) {
       trace('2nd loop: ' + i);
 }
}

If you would like the result outside of the function, use return varResult;

HTH
Cor



-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Alexander
Farber
Sent: dinsdag 23 december 2008 11:35
To: Flash Coders List
Subject: Re: [Flashcoders] Scope of variables declared in for loop

Hello, yes in AS3, but I think AS2 had the same irritating issue.

Sure you can put var i:int above.

But in many other languages (like C++, Java, Perl) you write something like

for (my $i = 0; $i < 10; $i++) {
      # XXX
}

an the scope of variable is limited to the loop only.

Regards
Alex

On Tue, Dec 23, 2008 at 11:22 AM, ekameleon <ekamel...@gmail.com> wrote:
> Your code is in AS3 ?
>
> In AS3 :
>
> var i:int ; // only one
>
> for ( i = 0; i < 10; i++)
> {
>       trace('1st loop: ' + i);
> }
>
> for ( i = 0; i < 10; i++)
> {
>       trace('2nd loop: ' + i);
> }
>
> The FlashPlayer 9 or 10 optimize the variables and you must implement a
> variable one time in the same expression of code ;)
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.0/1861 - Release Date: 22-12-2008
11:23

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

Reply via email to