|
![]() |
Steve
Theodore Casser
Code Poet
so how come bye parts printing?
David Newton wrote:
so how come bye parts printing?
Because myMethod() *returns* and continues its execution from where it was called.
...
Because myMethod() resumes execution at the point after it called itself: after the "nested" myMethod() returns the calling myMethod() keeps on going.
David Newton wrote:Seeing it quoted I probably could have said it more clearly, though...
How about:
Because myMethod() resumes execution at the point after it called itself: when the "nested" myMethod() returns the calling myMethod() keeps on going.
Hmm, maybe not ;)
It's just one of those things (like Lisp macros) you have to puzzle out until you hit that "moment of clarity". Stick with it--it's worth it.
Fred Hamilton wrote:Anyways, I'm joking. Sort of.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime: An example where recursion should be avoided (let's ignore StringBuffer.reverse() and StringBuilder.reverse() ):
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe wrote:
Rob Prime: An example where recursion should be avoided (let's ignore StringBuffer.reverse() and StringBuilder.reverse() ):
The only reason that recursion should be avoided in that example is for efficiency reasons. The recursive method is clearer and easier to write. I'd even note that there is an error in the looping version (although the compiler would have let you know about it).
My point is that recursion can sometimes be the clearer solution, but low level details about the call stack prevent it from being an optimal solution.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:
Fred Hamilton wrote:Anyways, I'm joking. Sort of.
I would hope so.
Don't get me started about those stupid light bulbs. |