if ()
{}else if (){}
else if (){}
else if (){}
else开发者_开发知识库{}
Do we need to have at least one else {}
?
Nope, an else
block is not required.
The following is perfectly valid:
if (....) {
}
else if (...) {
}
You do not need an else. If your conditions fail, no code will be executed without the else.
No it is not. Neither is it required when only using an if statement. Your also asking if it needs at least one else statement. The maximum is 1 else statement. You can not have if(){}else{}else{}
(Wouldn't make sense either :P)
精彩评论