Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: while loop question

by RichardK (Priest)
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
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 lurking in the Monastery: (11)
As of 2014-08-29 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (286 votes), past polls