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?

3rd Aug 2016, 10:21 AM
Andrea
Andrea - avatar
6 ответов
+ 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.
3rd Aug 2016, 10:33 AM
Sumitabha Banerjee
Sumitabha Banerjee - avatar
+ 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.
27th Aug 2016, 12:08 PM
beaTa
beaTa - avatar
+ 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' .
2nd Sep 2016, 6:02 AM
Adrian
Adrian - avatar
0
it helps in later processess like exception handling.
6th Sep 2016, 5:29 PM
Mohd.Tauheed Uddin Siddiqui
Mohd.Tauheed Uddin Siddiqui - avatar
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)
26th Oct 2016, 2:17 AM
Carlos Alberto Carvajal
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".
16th Jan 2017, 3:59 PM
al1c