When not to use recursion

Kewlx25

Distinguished
Recursion can get dangerous. Like many things, it is a tool, just don't abuse it.

Each function/method call does go on the stack, so don't use recursion for anything that may make many calls.
 

Wrong question.

You should be asking "When would I use recursion?"

Recursion should be used only in moderation, and only when an exit condition can be clearly defined, so as to avoid infinite recursion. Study the 'quicksort' algorithm for an example of how to use recursion properly. This is a good example because the same sort can also be written iteratively. Both have their uses.
 

TRENDING THREADS