I\'m writing a function that will call itself up to about 5000 times. Ofcourse, I get a StackOverflowError
. Is there any way that I can rewrite this code in a f
In most cases recursion is used in a wrong way. You shouldn't get a stack over flow exception. Your method has no return type/value. How do you ensure your initial Block b is valid?
If you are using recursion, answer yourself the following question:
Example:
my recursion anchor is n == 2 (result is 2), so I can calculate all results beginnging from this anchor.
my recursion step is n-1 (so each step I get closer to the solution (and in this fact to my recursion anchor))