Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: 'prev' in for loop

by gjb (Vicar)
on Dec 06, 2005 at 14:28 UTC ( #514467=note: print w/replies, xml ) Need Help??


in reply to 'prev' in for loop

prev simply isn't Perl. next and last are though.

You can always rewrite a for-loop from:

foreach my $item (@list) { something($item); }
to
for (my $i = 0; $i < @list; $i++) { something($list[$i]); }
By modifying $i you can get to the "previous" iteration (something like $i--. However, be careful not to create an infinite loop.

Hope this helps, -gjb-

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://514467]
help
Chatterbox?
[thezip]: Howdy y'all. Is it safe to just delete StrawberryPerl-> cpan->build directories?
[1nickt]: karlgoethebier Thank you!! How could I not have ever heard of this musician?
[choroba]: thezip should be ok.
[thezip]: It seemed so, choroba, but I don't want to confuse anyone (especially myself!)
[choroba]: thezip unless something like this happens to you.
[thezip]: I don't intend on doing any offline development in the Czech Republic soon, so i think I'm safe!
[thezip]: :-)
[choroba]: Yeah, there are countries with wifi everywhere

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-03-23 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (294 votes). Check out past polls.