What's the point of recursion when you can just use a while loop?

What's the point of recursion when you can just use a while loop?

Other urls found in this thread:

youtube.com/watch?v=Qk0zUZW-U_M
twitter.com/SFWRedditImages

While loops require state, which is inherently error-prone.

>require state
What's state?

>error-prone
What's an example that will fail in a while loop but doesn't in a recursion

What's the point of a loop, when you can just write a recursive function?

Honestly, this is the most retarded sentence in the context of programming I have ever read in life.

If you structure your recursive function properly, the compiler actually should translate it into a while loop (tail recursion).

Beyond that, it's a bit of an encapsulation thing, you know exactly what's going into and out of the function so it's easier to debug in a lot of situations.

...

But the poster was right, so if they were right and you disagree with them, you're an idiot who doesn't know what recursion or loops even really are.

Use whichever one is most readable for the situation.

Often with a tree structure recursion comes naturally.

It makes you feel smart

>Often with a tree structure recursion comes naturally.

This.

Whats the use of a recursive function if you can just copy and paste it

>Whats the use of a recursive function if you can just copy and paste it
What? Are you actually mentally retarded, or just trying to be?
If you copy the function, you can't call into it a variable number of times.

>not getting the joke
>calling others retarded

> trying to make a joke
> failing hard

>What's the point of recursion when you can just use a while loop?
Tree traversal made easier

youtube.com/watch?v=Qk0zUZW-U_M

the pajeets has evolved

With TCO those two codes are equivalent.
static int rec_fact_loop (int accu, int n) {
if (n 1) {
res *= n;
n--;
}
return res;
}

...

Because loops are inelegant as sh*t!

congratulations you dumb fuck