r/computerscience • u/ShadowGuyinRealLife • May 22 '25
Discussion Why Are Recursive Functions Used?
Why are recursive functions sometimes used? If you want to do something multiple times, wouldn't a "while" loop in C and it's equivalent in other languages be enough? I am not talking about nested data structures like linked lists where each node has data and a pointed to another node, but a function which calls itself.
106
Upvotes
View all comments
Show parent comment
1
u/stealthnyc May 25 '25
We don’t use recursion in production system mostly due it’s easy to miss a tricky edge condition that blows out your stack. Although recursion is much closer to how human thinks, using a loop as mentioned by OP is much safer from an engineering perspective