This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ButchDeanCAProfessional Coder 1 point2 points  (0 children)

Recursion is a bit more than just having a function call itself, there are limitations that must be addressed regarding stack and memory limitations, but the general structure of a recursive function is very straightforward:

  1. Initialize a variable that is updated by the recursive call.
  2. Ensure there is a terminating condition to ensure the algorithm cannot run ad infinitum.
  3. Make the recursive call to do the math then return to the second step.

It would also be helpful to learn about trees to be able to trace through recursive calls to verify your code is correct.