0
How does else 'ends' else if? From my view else is third/last option if previous two are incorrect, but why it 'ends' else if?
6 Réponses
+ 1
First the program checks for the condition in if. If it returns false then the subsequent else if conditions are checked. If all the else if conditions return false then the else is executed. You don't always need an else to end, but it is better to use it if all the condition checks fail. It actually does the work of default in the switch case statement.
+ 1
if (){ do this }
else if (){do this }
else {do that}
if the first statement is false go to next statement, if another is false do next one which must be true as there is no other option left.
+ 1
I agree with Andrea. I feel like in many languages I'm able to write an 'if' with just an 'else if' . There is not always a need or syntax requirement for 'else' to accompany 'else if' .
0
it helps in later processess like exception handling.
0
Is simple for use in 3 states, Yes or Possible or No (if - else if - else) Yes or No (if - else) only yes (if)
0
The "else" is absolutely not required.
What finishes the "else if" statement is the end of the brace block "}". There can be an "else", or there can be no "else".