Re: How can I STOP a cursed recursion?
- Posted by Dan Moyer <danielmoyer at prodigy.net> Jun 19, 2006
- 536 views
Dan Moyer wrote: > > Ricardo M. Forno wrote: > > > > Hi Dan. > > In any case, to stop a recursive procedure you must test its ending *before* > > calling it. If not, it will recurse forever, until it eats all available > > storage. > > Typical example (code not tested) > > > > function factorial (atom x) > > if x = 0 then > > return 1 > > end if > > return factorial(x - 1) * x > > end function > > Hi Ricardo, > > Here's like what I did, except that I have a number of other tests inside > the procedure which can re-call the procedue with different values to > act on, (those tests & consequences DID work), but the STOPPING didn't work: > > integer STOP > STOP = 0 > procedure Help() > if STOP then > return > end if > print(1,"help!") > Help() > if getTime() = 6am then > STOP = 1 -- How can I let the procedure *stop itself*!? > end if > > end procedure > Help() > > After I get some sleep, > I'll try Juergen's suggestion, which I think is to only call the procedure > from within itself when some "*not*-finished" condition is met, rather than > trying to use "return" to STOP it when the finished condition *is* met. > > Thanks, > Dan Ricardo, I see I should have paid more attention to what you said, because if my code really did what my example did, then the set STOP is never encountered. I'll have to look at my actual code closer in relation to what you said. Thanks, Dan