What is the difference between elseif and else




















The syntactic meaning is slightly different if you're familiar with C, this is the same behavior but the bottom line is that both would result in exactly the same behavior. The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to false , and the current elseif expression evaluated to true. Note : Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example.

Alternative syntax for control structures ». Submit a Pull Request Report a Bug. And does it make a difference? I thought else could only be used once. Switch statements cannot handle complex case expressions. Well I should say not to be used like that. Only with context can such a recommendation be made.

If statements allow multiple elseifs which can then be followed by else. There is no performance difference for the two, nor any logical difference. Ask Question. Asked 7 years, 11 months ago. Active 3 months ago. Viewed 77k times. They seem to do the exact same thing. Improve this question. Add a comment. Active Oldest Votes. Improve this answer. Damodaran Damodaran 9, 9 9 gold badges 56 56 silver badges 78 78 bronze badges.

Community Bot 1 1 1 silver badge. Deepak Deepak 1, 16 16 silver badges 28 28 bronze badges. In the second case, even if value of i is 0, all the following conditions are tested. No they are different. Foolish Foolish 3, 28 28 silver badges 41 41 bronze badges. I did know they were different, just wasn't sure exactly what the difference was. Suganthan Madhavan Pillai Suganthan Madhavan Pillai 4, 7 7 gold badges 39 39 silver badges 74 74 bronze badges.



0コメント

  • 1000 / 1000