Possible Duplicate:
else or return?
Consider a typical recursive function:
public int Fact(n)
{
if (n < 2)
{
return 1;
}
else
{
return n * Fact(n-1);
}
}
What is there a difference between writing it that way and this way?:
public int Fact(n)
{
if (n < 2)
{
return 1;
}
return n * Fact(n-1);
}
I prefer latter, specially when the recursive step consists of many lines of code. I don’t want to add unnecessary indentation.
Is there a practical difference or is this just a stylistic preference?
It’s just a matter of style. Usually I do not use else blocks when the end of the then block returns.