+ 3

Why should you always end IF & ELSEIF with ELSE statement?

Cant you just ask the program "if this do that if not, just ignore that this code exists". I am asking because the JS couse said: "The final else statement "ends" the else if statement and should be always written after the if and else if statements."

12th Sep 2017, 9:17 AM
Ståle Solberg
Ståle Solberg - avatar
4 ответов
+ 2
OK it appears you have misunderstood. It doesn't mean an else statement is required. It means that the else statement if used must be the last It means that when used else must go after the if else statements not before them.
12th Sep 2017, 10:33 AM
josh mizzi
josh mizzi - avatar
+ 4
else same as default when you using switch statement.
12th Sep 2017, 9:53 AM
Amethyst Animion
Amethyst Animion - avatar
+ 1
thank you. i thought that was it Josh because of python. I misunderstood the sentence and you cleared up its not different in JS
12th Sep 2017, 11:51 AM
Ståle Solberg
Ståle Solberg - avatar
0
That's fine.
12th Sep 2017, 1:21 PM
josh mizzi
josh mizzi - avatar