Multiple conditions in an if clause

后端 未结 9 1046
醉梦人生
醉梦人生 2021-02-02 06:44

If I have an if statement that needs to meet these requirements:

if(cave > 0 && training > 0 && mobility > 0 && sleep > 0)
         


        
9条回答
  •  后悔当初
    2021-02-02 07:17

    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
    }
    

提交回复
热议问题