[try Beta version]
Not logged in

 
Recursion Question

May 13, 2017 at 5:39pm
Let's say you have function fn(int a) {if (something) fn(a);}

so lets then say that on the first call, something is true, it calls fn(a) again, the second time something is false.

after the second fn call, does it return back to the first fn call and evaluate to the end, or is calling a recursive function act like a break in the first fn call?
May 13, 2017 at 5:47pm
It goes back through every call.
May 13, 2017 at 5:51pm
why would anyone use recursion? i've only seen it implemented one time to initialize gui elements. which could have been done through iteration, seems like recursion is very slow but i've been taught it in multiple coding classes.
May 13, 2017 at 5:56pm
People would use recursion when it's the right thing to do given all the constraints and requirements, such as the problem at hand, the facilities available, their own knowledge, ease of coding, the applicability of a recursive solution to the task, and various other factors.

This, of course, is the answer to the general question "Why would anyone use __ ?" , for any possible programming facility or technique.
May 13, 2017 at 6:22pm
May I have an example of when someone would use recursion?
May 13, 2017 at 6:42pm
Topic archived. No new replies allowed.