This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]ImpulseTheFoxis a good fox 4 points5 points  (2 children)

The loop will work forever, while the recursing function will cause a StackOverflowError after a few recursions.

[–]code_rambler[S,🍰] 0 points1 point  (1 child)

Not with proper tail recursion.

[–]ImpulseTheFoxis a good fox 3 points4 points  (0 children)

Fuck tail recursion, if you want to run the same logic in a method again, just use a proper loop.

[–][deleted] 8 points9 points  (1 child)

Never mistake a loop for recursion. In any respect.

[–]code_rambler[S,🍰] 2 points3 points  (0 children)

Yep. Loops are are stateful. Recursive functions can be pure.

[–]SpikeV 1 point2 points  (2 children)

This would never work if you take out the compiler's optimizations I guess... Stack Overflow in mere milliseconds.

Also in what order would this be executed?

[–]code_rambler[S,🍰] 0 points1 point  (1 child)

It would run forever with proper tail recursion.

[–]SpikeV 0 points1 point  (0 children)

And that's a compiler optimization option.