I'm writing a few very long functions that have to check values and return true
if a specific pattern has been found. I'm performing if
check and returning false
after one condition fails, never using the else
part like in this example
if (a < 0) {
return false;
}
// code
if (b < 0) {
return false;
}
// code
if (a + b / c > d) {
return false;
}
// code
Is this the correct approach or should I use else
instead? Is there any difference in performance or is it just a matter of readability?
if (a < 0) {
return false;
} else {
// code
if (b < 0) {
return false;
} else {
// code
if (a + b / c > d) {
return false;
} else {
// code
}
}
}