While you do have to manage state a lot more between "recursions", essentially you wrap the whole thing in a loop, then when you want to recurse you save state, then run continue myLoop;
— Implementing a stack to save state into is best because it then emulates the behavior of a real call stack