How Recursion Works
Why Stack Overflow recommends it
Stack Overflow users link it when answering beginner recursion questions and want to show how recursive calls and return values unwind on the call stack.
Recommended by 3 people across 3 different months, 2016 to 2017.
What it is
A short tutorial video that explains how recursion works by tracing recursive calls on the call stack, using a factorial calculation written in Java. It is presented by the YouTube channel davefeinberg.
What people said
Recommends et_l · 2016-09 · Stack Overflow · on “Heap's Algorithm Permutation JavaScript and Recursions' Stack?”
I'm not sure what you mean by understand recursion within this code in a loop If you mean you want to see the algorithm in a loop form rather than a recursion version you can see them one by side in pseudocode in the wikipedia page here [LINK] . For your questions within the code: how does this loop executes within the call stack? You are right to refer to the call stack, and this is a general question regarding recursion. If you don't understand how recursion works with the stack you can refer to this really nice and simple video [this video] that demonstrates recursive calls using factorial calculation in java (start around min 4:00). The line you look at is no different than any other line in
Recommends muds · 2017-07 · Stack Overflow · on “Exit the recursion without method returning anything”
To answer what I think your question means, all recursive functions must return. Otherwise they will never leave the function. I'm going to assume the eventual result you want is a recursive code for adding numbers. Here's all the issues with your code. Firstly, don't use the for-loop in your function . Recursion is used as a substitute for loops. Using both is like putting a for-loop within a for-loop that's attempting to do the same task. Second, recursive functions must have a return statement . Without this, it will not be able to break out. I'm not going to explain the basics of recursion here, but if you'd like, here's a guide on how recursion works [this video] . I'd recommend watching thi
Recommends Savir · 2017-12 · Stack Overflow · on “Return Value for Recursive Functions in Python”
The return value is `1` when you hit `j==1`, but be aware than in the `else` you're multiplying that by `j`. There's a video tutorial about it that I was watching just yesterday (for Java, but the general idea still stands) [this video]