When I create recursive methods, I often include a Depth-parameter, especially when I need some sort of bailout mechanism. The code will usually be something like this
procedure Recurse(<Params>; aDepth : integer = 0);
begin
if aDepth > SomeLimit then
begin
//Tidy up, return best result found>
exit;
end;
<stuff>
if <Condition> then
Recurse(<Params>; aDepth+1)
else
begin
//Tidy up, return result of endnode>
end;
end;
And I call it without the Depth-parameter
Recurse(<Params>);
Is there another way to easily find the depth?