if子句中的多个条件 [英] Multiple conditions in an if clause
本文介绍了if子句中的多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的if语句需要满足这些要求:
If I have an if statement that needs to meet these requirements:
if(cave > 0 && training > 0 && mobility > 0 && sleep > 0)
有没有办法说它们都大于零?只是为了更有效的DRY代码?
Is there any way to say that all of them are bigger than zero? Just for more efficient DRY code?
类似于:
if(cave, training, mobility, sleep > 0)
推荐答案
您可以使用 Math.min 获得最低价值,然后你只需要对下限进行一次检查。
You could get the lowest value with Math.min, and then you only need one check against the lower bound.
if(Math.min(cave, training, mobility, sleep) > 0) {
//do something
}
这篇关于if子句中的多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文