[Israel.pm] C style for loop

sawyer x xsawyerx at gmail.com
Thu Mar 8 14:37:52 PST 2012


On Thu, Mar 8, 2012 at 11:58 PM, Roman M. Parparov <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>> 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.

No reason not to move on to a more readable (and in calculated instances
even FASTER) range-style for() loop instead. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20120309/b8ff91fc/attachment.htm 


More information about the Perl mailing list