Mail Archives: djgpp/1999/12/12/03:47:45
"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 -