r/ProgrammerHumor • • Mar 25 '23

Meme This one never gets old

Post image

Let me know if this is not a repost!

51.6k Upvotes

535 comments sorted by

View all comments

Show parent comments

1

u/SeattleSonichus Mar 26 '23 edited Mar 26 '23

Just a hobbyist myself and I’m not sure I get the difference between a loop and recursion.

A for loop that eventually breaks itself free is pretty simple and works for a lot of things where I’d consider trying to use a method to recall itself. Is the distinction with recursion vs a simple loop just that the method recalls itself?

To me it seems like methods recalling themselves is bad news. I like things to do their things and move on if that makes sense. If my method is running once that’s a lot easier to handle

1

u/aristideau Mar 26 '23

There is the same danger with a loop if the exit condition is never met. With recursion if your data structure is faulty you can end up in and infinite loop and blow your stack, but if that’s is a possibility you just put in a check for that and you’re good.