I converted the pseudo-code here into C#, and have it recursively repeat 10,000 times. But I get a C# runtime error, StackOverflow Exception after 9217
StackOverflow Exception
9217
You cannot prevent it, the function calls itself too many times; there's a limit on how deep the call stack can get, and your function reaches it.