How exactly does recursion work?

Yes, I agree that recursion is good to learn. I also agree that I don’t use it much. In 3 years as a professional developer, I’ve written one recursive function and only seen one other one.

They are really useful for a narrow set of problems. The time I used one was traversing a tree. It could have been done with loops but would have been very messy.

The other reason to learn recursion is that it will show up on interviews sometimes - people think they’re cool. The other reason is that it is good exercise for your “coder brain”.

I agree that there are plenty of discussion of this on the forum. I’ve had two recent ones, here and here. There are many others on the web. And I think understanding the call stack can be a visual thing so checkout out some youtube videos can be a good thing.

1 Like