Hard and fast rule about writing recusive functions and methods: you ALWAYS have to have a conditional (usually an if statement) based on the function parameters (directly or indirectly) where one branch calls the function recusively, and one branch does not. Both branches MUST be possible to execute. It's really easy to write the recusive cases (at least I've always thought so), but writing the non-recusive cases tends to be more troublesome.
When I was taking my "intro to programming" course, the instructor had a very clever idea for demonstrating recusion. Get a stack of index cards. Put one down in front of you, and write the parameters to your function across the top. Go through your function body, writing down all the variables you set and/or change on the same card. When (if!) you get to the recusive call in that function, just add a new index card, again writing the parameters at the top. When you get to the end of a given function, remove the card from the stack. If there are more cards, pick up with them where you left off, otherwise you're done. It's really simple, but (I thought) it was a great way to show that there is nothing magical about recursion, just a different way of doing a loop. There are a few differences, but in general they can solve the same problems. Cheers, barneyb > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Nando > Sent: Sunday, November 30, 2003 11:26 PM > To: [EMAIL PROTECTED] > Subject: [CFCDev] recursive functions > > I got a recursive function working to generate a site map > today based on an > example i found, (very cool how that works! many thanks go to Barney > Boisvert for the original idea), but i'm not sure i could > have come up with > that on my own. Does anyone know of any good resources on recursive > functions? I'm still finding the concept hard to get my head around. > > > ---------------------------------------------------------- > You are subscribed to cfcdev. To unsubscribe, send an email > to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' > in the message of the email. > > CFCDev is run by CFCZone (www.cfczone.org) and supported > by Mindtool, Corporation (www.mindtool.com). > > An archive of the CFCDev list is available at > www.mail-archive.com/[EMAIL PROTECTED] > ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com). An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
