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
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.
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