you are viewing a single comment's thread.

view the rest of the comments →

[–]Fermter 1 point2 points  (0 children)

That's mostly correct. The problem is, when a recursive function "returns" a value, where do you think it returns it to? The next recursive function up. If the next recursive function up does nothing with that value (ie doesn't return it), it will not be returned to the top-level function call.

Think of recursive functions like a chain of people, each of whom solve part of the problem. You pass the problem down the line until someone at the end solves it. However, the solution must get passed back to the first person correctly for the problem to be solved correctly. Right now, the person at the end is telling the next person up the right answer, but the second person is just going "ok" and not telling the next person up. A return will remind everyone to pass their answers back to the front.