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

Re: "return" to break out of a loop

by moritz (Cardinal)
on May 13, 2008 at 14:25 UTC ( [id://686269]=note: print w/replies, xml ) Need Help??


in reply to "return" to break out of a loop

IMHO there's nothing wrong with it.

Some languages (like Eiffel) disallow such a construct to make it easier to prove the correctness, and to get a better idea about the flow of the program (which is in this case: it runs through the method until it hits the end of that method).

But I found return and last useful at times, and wouldn't want to miss it.

Replies are listed 'Best First'.
Re^2: "return" to break out of a loop
by phaylon (Curate) on May 13, 2008 at 18:49 UTC
    For this to _really_ be nice, stuff like if would have to return the last value of the executed block:
    sub is_even { if (shift % 2) { 0 } else { 1 } }
    We already have the ternary operator, but I find it can get hard to maintain when used often in one statement. Sparkling some do { .. }'s in only makes it a bit better.

    Ordinary morality is for ordinary people. -- Aleister Crowley

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found