else
due to return
CS-R1044The block under else-if
is executed only when the preceding if
condition evaluates to false
. However, if the last statement of the block under the preceding if
statement is a return
statement, else
in else-if
becomes redundant as the controller never reaches it, and, it can be written as a separate if
statement.
if (x == 1) {
// Do something
return;
} else if (x == 2) {
// Do something
}
if (x == 1) {
// Do something
return;
}
if (x == 2) {
// Do something
}