Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Nested Loops vs Good programming

by snopal (Pilgrim)
on Nov 14, 2008 at 14:09 UTC ( #723656=note: print w/replies, xml ) Need Help??

in reply to Nested Loops vs Good programming

Recursion is your friend. By understanding both scoped variables and how to package and pass your current values forward in the recursive call, you can have both your current virtually unlimited level, and all previously detected superior values at any moment in time.

Be aware that recursion is memory intensive, so this ability gives you extreme flexibility, at several costs. First, it becomes a memory hog for depth-wise structures which may leave you "out of memory". Second, you still have the reponsibility to eventually leave the recursion in an orderly fashion (usually by return at the end of each level).

It is not good practice to step out of recursion before unwrapping all the depth you have accumulated. It is better to pass out your constructed structure or build an external structure if you need values outside the recursion.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2020-10-26 16:47 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (252 votes). Check out past polls.