in reply to RE (6) Adam: Answer: How can I add all the numbers in an array with out doing a foreach loop?

in thread How can I add all the numbers in an array with out doing a foreach loop?

Sorry Nuance, Recursion is NOT a loop.

Recursion works by building up the stack, delaying evaluation until the end. A loop evaluates as it goes. There is a big difference between the two.

Recursion works by building up the stack, delaying evaluation until the end. A loop evaluates as it goes. There is a big difference between the two.

Think about it this way: The recursive method that I posted says to add the first number to the sum of the other numbers. That can't be done until the sum of the other numbers is known, so it puts the number on the stack and trys to sum the other numbers by the same method. It does this, pushing the list onto a stack, until there is only one number left, then it sums the stack. This is not a loop. Its not even close.

Replies are listed 'Best First'. | |
---|---|

RE: Recursion is not a looping construct.
by lhoward (Vicar) on Jun 11, 2000 at 02:28 UTC | |

RE: Recursion is not a looping construct.
by KM (Priest) on Jun 11, 2000 at 05:49 UTC |

In Section
Seekers of Perl Wisdom

Comment onRecursion is not a looping construct.