You should ask the creators of AS3 that. Its their choice -----Oorspronkelijk bericht----- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens jonathan howe Verzonden: maandag 24 maart 2008 9:35 Aan: Flash Coders List Onderwerp: Re: [Flashcoders] Variable scope within for loops:reusingiteratorvariables
I totally agree with your explanation, and the part that I am being pouty about is: "Why isn't the variable's scope confined to the loop?" a la: for (var i:int = 0; i < limit; i ++) { // variable is instantiated // scope of variable } // variable is discarded instead of it being what several of you have described. -jonathan On Mon, Mar 24, 2008 at 4:22 AM, Cor <[EMAIL PROTECTED]> wrote: > Indeed, I was talking about AS3 too. > > For reasoning: Its like the real world -> every object is UNIQUE, > therefor there can only exist ONE of it. > You can make copies (instances) but they will have there own unique name. > You can use it as much as you like but you can't CREATE the same > object (within its scope) again. > > Does this explain it for you? > > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Namens jonathan > howe > Verzonden: maandag 24 maart 2008 9:14 > Aan: Flash Coders List > Onderwerp: Re: [Flashcoders] Variable scope within for loops: > reusingiteratorvariables > > Hmm... it is within a class... and that's when I'm getting the warnings. > Or > did you mean just in general to reiterate that variables are locally > scoped to functions and classes and not to for loops? > > I should have mentioned in my subject that this is AS3. So far > everyone's alternatives and explanations make sense, I am just curious > now as to the reasoning. Either this is a change from AS2 -> AS3 or > since AS2 wasn't as strict, it let me do it before. Maybe the > explanation lies in the ECMA guidelines somewhere. Anyway, thanks for the discussion, gang. > > -jonathan > > > On Mon, Mar 24, 2008 at 3:53 AM, Cor <[EMAIL PROTECTED]> wrote: > > > Using it youre way is possible when you do it within a function or > > class because then they are private by default > > > > Other you could use it this way > > Example 1: > > > > for (var i:int = 0; i < someArray.length; i ++) { > > // do something cool > > } > > > > for (i = 0; i < someOtherArray.length; i ++) { > > // do something even cooler > > } > > > > ----------------------------------------------- > > Example 2: > > var i:int; //or uint if I is never negative > > > > for (i = 0; i < someArray.length; i ++) { > > // do something cool > > } > > > > for (i = 0; i < someOtherArray.length; i ++) { > > // do something even cooler > > } > > > > No virus found in this outgoing message. > > Checked by AVG. > > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > > 23-3-2008 18:50 > > > > > > _______________________________________________ > > Flashcoders mailing list > > Flashcoders@chattyfig.figleaf.com > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > -- > -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 > > > -- > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > No virus found in this incoming message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > > No virus found in this outgoing message. > Checked by AVG. > Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: > 23-3-2008 18:50 > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- -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 -- No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 No virus found in this incoming message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 No virus found in this outgoing message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1340 - Release Date: 23-3-2008 18:50 _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders