0

Else if

Is there a diffrence betwen else if or just else

5th Dec 2016, 10:50 PM
Retnom
Retnom - avatar
2 Answers
+ 1
An else if block runs if it fulfills another condition, but didn't fulfill any previous if statement; an else block runs no matter what if no other if or else if block is executed. For example: if(x==1) y=1; else if(x==2) y=4; else y=0; Let's assume that an integer x is already defined somewhere else. If x is one, then it fulfills the first if statement, and y is set to one. If x is two, then the first condition is not met, but the second one is; y is therefore set to 4. If x is any other number, then neither of the if statements are true, so y is set to zero.
5th Dec 2016, 11:02 PM
Matt Buckley
Matt Buckley - avatar
0
Thanks :D
5th Dec 2016, 11:04 PM
Retnom
Retnom - avatar