I know this is going to not be the same across all languages, but it's something I've wondered for awhile.
Since the title isn't very clear, is there a technical difference between
if (...) {
// ...
} else if (...) {
// ...
}
and
if (...) {
...
} else {
if (...) {
...
}
}
I know from a practical perspective, they will do the same thing, and there are readability reasons for choosing one over the other, such as if the second if
doesn't relate directly to the first.
But from a technical perspective, I'm not sure. Do compilers tend to do something special with an else if
, or is it handled as though it were a single line thing, like:
if (...)
singleLine();
but looking like:
else
if (...) // Counts as just a single line command
Hope that makes it clear what I'm asking. Is there a technical difference between the two ways of doing it, and is there any disadvantage to using the else { if
style?