I've been trying to place a Do Loop within a recursive Subroutine and placing the stop value within the same recursive Subroutine. I was thinking the stop value may need to be in the Do Loop itself rather than the recursive subroutine. But....seems recursion best lives in a subroutine and not meant be associate with Do Loops.
Thanks Guys
There's no issues with a DO.. LOOP being in a recursive sub. Take the following as an example, based on your original main loop:
RecursiveMain 0, 100
Sub RecursiveMain
(b
, bLimit
) b = b + 1
a = a + 1
Print " Value of A is "; a;
" Value of B is "; b
If b
<> bLimit
Then RecursiveMain b
, bLimit
You just need to choose the point where you want the recursion to occur at; there's no issues at all with having DO..FOR..WHILE.. or any other keyword inside your recursive looping.
The real question is: WHY would you want recursion when you don't need it? It eats up stack space, has a tendency to overload and crash programs when used excessively, and isn't honestly any faster or more efficient. Personally, I'd much rather be working with the original code than trying to wrap my brain around what's going on with the recursive routines. It's not that I
can't sort them out and understand them; it's that I can't sort them out and understand them
as easily as I can with a simple DO... LOOP.
Maybe that's just me, but anytime recursion is used, I have to take a moment to sit back and visualize and sort out what's going on when I see a function call itself. It just adds to the complexity of things, and if I can get by without having to use it in my stuff, generally speaking that's what I try and do.