Re: How can I STOP a cursed recursion?
- Posted by Juergen Luethje <j.lue at gmx.de> Jun 19, 2006
- 541 views
Dan Moyer wrote: <snip> > Is there some way to just STOP a procedure, even if it has been working > recursivly?? Yes, it is. > Or maybe recursion is supposed to be limited to FUNCTIONS? No. > procedure Help!() > print(1,"help!") > Help{} > -- How can I stop!? > end procedure > > Help!
integer Count, NumTimes procedure Help() puts(1,"Help!\n") Count += 1 if Count < NumTimes then Help() end if end procedure Count = 0 NumTimes = 3 Help()
The code above prints "Help!\n" three times. Often it is nice to use an additional non-recursive routine, which "wraps" the recursive routine, e.g.:
integer Count, NumTimes procedure Help() puts(1,"Help!\n") Count += 1 if Count < NumTimes then Help() end if end procedure global procedure Call_Help(integer times) -- This is the routine which is called by the user. Count = 0 NumTimes = times -- copy to local variable Help() end procedure Call_Help(3)
Regards, Juergen