Quote:Original post by TommySauder
Just wondering if there's an actual use to recursion in games... seems kinda pointless and a complete waste of memory+cpu power.
For the most part, you can change an iterative loop into a recursive loop and vice versa. The only difference will be that the recursive version will pile up on the stack. However, there's more to the story than just that:
1) Some algorithms are much clearer in one form than the other. If you can spare the "memory+cpu", then use the clearer one.
2) If you compiler can perform tail-call optimizations, there will be no difference in "memory+cpu" (it essentially turns a recursive algorithm into its iterative version). Thus, you can feel free to choose the clearer form with no performance worries.
3) Unfortunately, I don't think many C/C++ compilers do this optimization (I think GCC will do it?). On the other hand, C/C++ aren't the only languages out there.