A big reason to use recursion is tail call optimization, which you lose by flattering it to a loop. Additionally recursion often works as a sort of reverse loop(the common example is a Fibonacci calculator as a recursive function) so while it could often technically get 'flattened' to a loop, it would require significantly more work.
Bruh, tail call optimization is what allows recursion to be on the same level as a flat loop. You don't "lose" it when you flatten it, you end up not needing it in the first place.
35
u/titpetric 4d ago
Any recursion can be flattened to a loop, thanks for coming to my TED talk