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

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?

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 avoiding work at the Monastery: (10)
As of 2015-11-26 10:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (697 votes), past polls