Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Foreach Loops

by Roy Johnson (Monsignor)
on Mar 15, 2005 at 22:09 UTC ( #439791=note: print w/ replies, xml ) Need Help??


in reply to Re: Foreach Loops
in thread Foreach Loops

You should really put the counter increment in the continue block, though, in case of next or redo. Compare:

my @arr = ('a'..'m'); my $i=0; foreach (@arr) { # stuff goes here next if $i%4 == 0; print "$i: $_\n"; } continue { ++$i } $i = 0; foreach (@arr) { # stuff goes here next if $i%4 == 0; print "$i: $_\n"; ++$i; }

Caution: Contents may have been coded under pressure.


Comment on Re^2: Foreach Loops
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://439791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-07-10 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (216 votes), past polls