ProAnswers.org

Should a function have only one return statement?

I often have several statements at the start of a method to return for “easy” situations. For example, this:

public void DoStuff(Foo foo)
{
if (foo != null)
{

}
}

… can be made more readable (IMHO) like this:

public void DoStuff(Foo foo)
{
if (foo == null) return;

...

}

So I think it’s fine to have multiple “exit points” from a function/method.