Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

exiting two loop levels

by jeteve (Pilgrim)
on Sep 21, 2006 at 10:17 UTC ( #574090=perlquestion: print w/replies, xml ) Need Help??
jeteve has asked for the wisdom of the Perl Monks concerning the following question:

Hi wise fellow monks.

I'm wondering how to exit two loops levels with a single instruction.

What I'm searching for whould be some kind of 'last 2' which would exit two levels.

-- Nice photos of naked perl sources here !

Replies are listed 'Best First'.
Re: exiting two loop levels
by GrandFather (Sage) on Sep 21, 2006 at 10:21 UTC
    OUTER: while (...) { while (...) { ... last OUTER; } }

    /me stands back and waits for the slapped forehead sound.

    DWIM is Perl's answer to Gödel
Re: exiting two loop levels
by davorg (Chancellor) on Sep 21, 2006 at 10:23 UTC

    You need labelled loops.

    OUTER: while ($something_is_true) { INNER: while ($some_other_thing_is_true) { last OUTER if $you_want_to_quit_outer_loop; last INNER if $you_want_to_quit_inner_loop; } }

    See Compound statements in perldoc perlsyn for details.

    Update: Added ':' to labels.


    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: exiting two loop levels
by VSarkiss (Monsignor) on Sep 21, 2006 at 14:26 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://574090]
Approved by GrandFather
[erix]: my objection to sigs is just that they take screen space. ( Some monks would have *several* slogans underneath a 1-liner reply )
[Discipulus]: a solution would be disabiltate sig as default and let users to show them
[karlgoethebier]: now it's getting weird...
[GotToBTru]: 'getting'?
[Discipulus]: why karlgoethebier ?

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (15)
As of 2017-06-22 12:46 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.