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
2
u/apnorton Devops Engineer | Post-quantum crypto grad student Jun 06 '25
I think you've misinterpreted what I was trying to say.
My point is that language-level recursion support is not a necessary requirement for the language to be Turing complete. (i.e. "You don't need it [language-level recursion support] to be Turing compete.") The reason for this is that, if you have a loop and a stack, you can emulate what recursion does.
My comment does not claim that a language with a loop + a stack needs recursion as well in order to be Turing complete. :)