开发者

Does if with ifelse ,ifelse needs to have at least one else statement

开发者 https://www.devze.com 2023-01-30 18:55 出处:网络
if () {}else if (){} else if (){} else if (){} else开发者_开发知识库{} Do we need to have at least oneelse {}? Nope, an else block is not required.
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)

0

精彩评论

暂无评论...
验证码 换一张
取 消