Re: How can I STOP a cursed recursion?

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu