[Israel.pm] C style for loop
Roman M. Parparov
roman at parparov.com
Thu Mar 8 15:13:12 PST 2012
On 3/8/12 2:37 PM, sawyer x wrote:
> On Thu, Mar 8, 2012 at 11:58 PM, Roman M. Parparov <roman at parparov.com
> <mailto:roman at parparov.com>> wrote:
>
> On 2/25/12 3:46 AM, sawyer x wrote:
> > On Fri, Feb 24, 2012 at 5:55 PM, Roman M. Parparov <roman at parparov.com
> <mailto:roman at parparov.com>
> > <mailto:roman at parparov.com <mailto:roman at parparov.com>>> wrote:
> >
> > And if you need steps different than one? Non-linear? :)
> >
> >
> > Relatively rare. Most uses are for single step.
> > If you happen to fall on a case using other steps, you would know to
> ignore my
> > warning of C-style for loops. :)
> >
> >
> Recently I found another use:
> If I need the index value after the loop. :)
>
>
> Nope! :)
>
> Writing a C-style for() loop does not give you the index value if you define
> it using my().
> If you write:
> for ( my $i = 0; $i < 10; $i++ ) {...}
> you will not be able to access $i afterwards, since it will only exist in the
> scope of the for().
> Same as with range-style for() loop.
>
But if I my() the variable outside the loop, then in C-style it is defined,
while in range-style it is not.
> No reason not to move on to a more readable (and in calculated instances even
> FASTER) range-style for() loop instead. :)
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
More information about the Perl
mailing list