Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: while loop question

by RichardK (Parson)
on Sep 06, 2012 at 12:13 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 10:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found