[Israel.pm] C style for loop
Roman M. Parparov
roman at parparov.com
Thu Mar 8 13:58:15 PST 2012
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. :)
R.
> R.
>
> On 2/24/12 12:01 AM, sawyer x wrote:
> > On Fri, Feb 24, 2012 at 9:41 AM, Stefan Hornburg (Racke)
> <racke at linuxia.de <mailto:racke at linuxia.de>
> > <mailto:racke at linuxia.de <mailto:racke at linuxia.de>>> wrote:
> >
> >
> > How do you write for loops without C-style where you need a running
> > index inside the loop code?
> >
> >
> > Simple:
> > foreach my $idx ( 0 .. $#array ) {
> > print $array[$idx], "\n";
> > }
> >
> >
> >
> > _______________________________________________
> > Perl mailing list
> > Perl at perl.org.il <mailto:Perl at perl.org.il>
> > http://mail.perl.org.il/mailman/listinfo/perl
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il <mailto:Perl at perl.org.il>
> http://mail.perl.org.il/mailman/listinfo/perl
>
>
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
More information about the Perl
mailing list