www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/12/03:47:45

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Use of recursion
Date: 11 Dec 1999 23:00:11 -0800
Organization: InterWorld Communications
Lines: 31
Message-ID: <83hfho1w5g.fsf@mercury.st.hmc.edu>
References: <82vfqn$6ce$1 AT mango DOT singnet DOT com DOT sg>
NNTP-Posting-Host: mercury.st.hmc.edu
X-Trace: nntp1.interworld.net 944982088 1643 134.173.45.219 (12 Dec 1999 07:01:28 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 12 Dec 1999 07:01:28 GMT
X-Newsreader: Gnus v5.7/Emacs 20.4
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Yong-Kwang Goh" <ykgoh1 AT singnet DOT com DOT sg> writes:

> I've a function that draws borders around bitmaps to make them
> appear outset (popup) or inset (sunken). In anyway, it means giving
> the bitmaps a 3D look if you don't get what I mean.
> 
> Somehow, it can be programmed to achieve the effect in 2 ways:
> using recursion or normal looping.
> 
> Now, I've a dillema -- should I use recursion or looping after all.
> AFAIK, recursion is a very useful and good programming technique,
> but one which gobbles up computing resources and *must* be
> used carefully. Looping is more efficient but usually more complicated
> than using recursion.
> 
> I wonder if recursion *is faster* than looping.

Generally not.  If you think about it, all the same code has to be
executed.  (Unless this is different for your specific algorithm.)

> When should I use recursion since it can be replaced with looping
> most of the time?

You've already discovered it -- it's often much simpler to write.  And
when you don't care about performance, the saving in coding time is
nice.

-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019