comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Recursive function/procedure
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Recursive function/procedure [message #15150 is a reply to message #15133] Fri, 23 April 1999 00:00 Go to previous messageGo to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Tri VU KHAC wrote:
>
> Hi folks,
> How to write a recursive function/procedure ?
> What are programming problems of this technique in IDL ?
> Thanks for help.
> Best regards,
> Tri

since the first question has been answered let me address the second
one:
as always with recursive procedures, you must take care not to run into
infinite loops (and there is some limitation as to how many recursions
you can make although I don't know the number now). Hence, a "safe"
recursive procedure would look like this:

pro recurse,level

MAX_LEVEL = 1000 ; or whatever is reasonable

if (n_elements(level) eq 0) then level = 0 ; main entry level
if (level gt MAX_LEVEL) then begin
message,'Maximum number of iterations exceeded!' ; optional +
,/Continue
return
endif

; *** do your stuff here

recurse,level+1

; *** do more stuff here

return
end



Regards,
Martin.

--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Engineering&Applied Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax : (617)-495-4551

e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/
------------------------------------------------------------ -------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Recursive function/procedure
Next Topic: Re: Mac SEND_EVENT

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 00:54:24 PDT 2025

Total time taken to generate the page: 1.04162 seconds