Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: while loop question

by RichardK (Vicar)
on Sep 06, 2012 at 12:13 UTC ( #992073=note: print w/ replies, xml ) Need Help??


in reply to while loop question

You can always wrap your while loop in a simple block with a label and use last LABEL

So something like this :-

use v5.14; use warnings; my @l = (0..5); sub test { my ($match) = @_; LOOP: { for my $v (@l) { if ($v == $match) { say "found"; last LOOP; } } # fell off the bottom say "not found"; } } test(4); # found test(7); # not found


Comment on Re: while loop question
Select or Download Code
Replies are listed 'Best First'.
Re^2: while loop question
by Freezer (Sexton) on Sep 06, 2012 at 13:34 UTC
    Nice ideas. The trouble is, as well as wanting to be able to say last LINE (or LOOP) I want to be able to say  next LINE if $1 < $start_point; and your solution doesn't offer that possibility.

      Of course it does :). It works in just the same way as using next/last in any nested loops.

      OUTER: { INNER: while(1) { next INNER if this(); last OUTER if that(); } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2015-07-30 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls