in reply to recursion basics
The (recursive) call to binary() occurs between the "print ABOVE" and "print BELOW"
This means that before the BELOW gets printed, the sub is called again, going through he "ABOVE" logic.
This causes ABOVE to be printed again .. and again on each recursive call, not giving BELOW a chance until the recursion completes.
Now - the RECURSED instance also goes through the same steps, and is unable to print BELOW until the NEXT recursion completes.
So, the "BELOW"s stack up and are released together as the recursion unwinds.
If you use the perl "-d" switch, you can step through the recursion, and even do a "T" stack trace to see what the sequence is.
"Despite my privileged upbringing, I'm actually quite well-balanced. I have a chip on both shoulders." - John Nash
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: recursion basics
by wrinkles (Pilgrim) on Jun 23, 2015 at 06:35 UTC | |
by aaron_baugher (Curate) on Jun 23, 2015 at 06:48 UTC | |
by robby_dobby (Hermit) on Jun 23, 2015 at 06:43 UTC | |
by Anonymous Monk on Jun 23, 2015 at 09:32 UTC |