shortHand if else-if和else语句 [英] shortHand if else-if and else statement
本文介绍了shortHand if else-if和else语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我嵌套了if else语句,我在下面的两个语句中添加了该语句,而不是用很多行来简化它。
I have nested if else statements, which I added below in two statements, Instead of having a lot of lines I am looking to shorthand it.
任何人都可以帮忙吗
在Statement1的以下语句中:a& b和C& d,a,b,c,c是数组。
在statement2中为其关键字。
In Below statements in Statement1: a&&b and C&&d, a,b,c,c are arrays. In statement2 its a keywords.
声明1:
if((a && b)!== -1){
abc ="hai"
}
else if ((c && d)!== -1) {
abc="hello"
}
else{
abc="Hurray"
}
声明2:
if(a==="abc"){
if(bb==="def"){
amd ="hello"
}
else if(bb==="ghi"){
amd ="hai"
}
else{
amd = "Hurray";
}
}
else if(a==="qwe"){
if(aaa==="ddd") {
amd = "Hurray Hi";
}
else{
amd = "Hurray bye";
}
}
推荐答案
声明:1可以写为,
abc = (a !== -1 && b!== -1) ? "hai" : (c !== -1 && d!== -1) ? "hello" : "hurray";
因此,基于此尝试为语句2编写自己的代码[提示:请使用 switch
为此]
So based on this try to write your own code for the statement 2 [Hint : use switch
for that]
这篇关于shortHand if else-if和else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文