Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: while loop question

by RichardK (Parson)
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

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?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2016-10-21 15:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.