03-16-2010, 01:05 AM
Well... I always thought of recursion as something that calls itself in order to perform an action multiple times. Like this:
[PoolFill]
Pool fill with 15 gallons of water;
If pool is filled
>(Do nothing)
Else
PoolFill();
See, the method will keep calling itself over and over automatically until the pool is filled.
Now, recursion can also be something like:
[HareHop]
bunnyHops decrement by 1
Bunny move forward 1 meter
If bunnyHops > 0
>HareHop();
Else
>(Do nothing)
This is nearly the same setup, but using a number variable called bunnyHops as the condition which stops the recursion. By setting that variable to a certain number before you call the method HareHop for the first time, you can guarantee it will be called that many times and the bunny will move forward that many times.
I know for a fact that THAT'S recursion. But to make sure, let me look it up real quick...
And it looks like I'm right. To be recursive, a method or function must call itself as the very last command it executes (unless of course you put a conditional stop, as i did, in there).
|