Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Desparate behavior in loop labels

by Errto (Vicar)
on Aug 29, 2007 at 03:05 UTC ( #635718=note: print w/ replies, xml ) Need Help??


in reply to Desparate behavior in loop labels

Here is an example:

sub foo { print $_; last if $_ >= 3; } sub bar { for (1 .. 10) { foo; } } bar;
This script will stop printing after "3". This is because calling last from inside foo jumps out of the loop it's in, even though that loop is defined in bar. By contrast, in languages like C or Java, the equivalent calls (break and continue) are simply illegal outside loops.


Comment on Re: Desparate behavior in loop labels
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2015-07-03 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls