r/computerscience • u/UselessPlinth • May 03 '21
When to use recursion?
So I am getting a little bit ahead of myself here, I'm still in high school and I'm entering (hopefully) AP Java next year (or computer science A). One of the topic there is recursion, and I've done a little digging, and I find recursion really interesting, but what I was wondering was when do programmers use recursion? Like, can a for loop just do the job or does it help with computer memory and processing, when is the best time to use recursion?
141
Upvotes
1
u/[deleted] May 04 '21
https://en.wikipedia.org/wiki/Subroutine#Jump_to_subroutine
This is what I mean. I learned assembly on the 8086. My professor expounded upon how monumental this invention was. Before the specialized "Subroutine" instructions, they were literally just divisions in your code separated by regular jumps.