Recursive Methods: An Overview
A recursive method is a method that calls it's self at some point within its running.
Recursive methods are often used when using a form of a loop would cause long run times.
Recursive Methods: A Quick Guide
The following are things to keep in mind when writting a recursive method:
- Write a base case that causes the method to return/not continue. Put that case
near the top before any recursive calls
- Be careful to avoid recursive cases that will cause infinite calls. Make sure
something incraments or a base case is able to be reached.
- Take a step back (litterally) and relook at how you have written the method.
Can things be simplified? Can they be condensed? Are you missing a case? Take
some time and think about something else
Recursive Methods: Further Reading
This article from
GeeksForGeeks is a
great resource for futher reading on recursive methods!