Code inspection: Tail recursive call can be replaced with loop
A tail-recursive call is a recursive call that is the last action in a method. These calls can be safely replaced with a loop, which is often more efficient and prevents potential StackOverflowException when the recursion depth is large.
This inspection identifies tail-recursive calls and suggests converting them into loops.
void DoStuff()
{
if (Environment.TickCount % 2 == 0) DoStuff();
}
void DoStuff()
{
while (true)
{
if (Environment.TickCount % 2 == 0) continue;
break;
}
}
The quick-fix wraps the method body in a while (true) loop and replaces the tail-recursive call with a continue statement.
11 March 2026