Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Control Flow - Multiple returns or nested conditionals

by FloydATC (Deacon)
on Oct 08, 2010 at 21:32 UTC ( #864284=note: print w/replies, xml ) Need Help??


in reply to Control Flow - Multiple returns or nested conditionals

For complex logic, I always use a single exit point to ease code maintenance. When the code logic dictates different types of returns depending on the circumstances I try to use some sort of state machine and put my exit points at the bottom so atleast I don't have to hunt them down later.

Deeply nested unless..else statements with a few negated or clauses and recursive sub routine calls can be enough fun without the added confusion of multiple exit points :-)

For a sequence of tests like in your post though, there's no reason to perform any more processing if one test fails so return the status/error/result/whatever and get out of there. IMHO.

-- Time flies when you don't know what you're doing

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://864284]
help
Chatterbox?
[shmem]: Lanx: that just enables the border. Looking up style attributes...
[LanX]: ?
[karlgoethebier]: code><table style="border: 1px solid black;}"></code> same for th and td ?
[shmem]: my scratchpad
[karlgoethebier]: oops!
[shmem]: karlgoethebier: np, got it. But doesn't either :-/

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-07-24 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (356 votes). Check out past polls.