有没有使用if语句逻辑运算符的任何好处? [英] Is there any benefit of using if statement with logical operator?
问题描述
我知道的 if语句的,可以以各种方式,如用逻辑运算符的语句中使用, IF ... ELSE 和嵌套如果语句的等。
I know that if statements can be used in various ways, such as an if statement with a logical operator, if...else, and nested if statements etc.
当使用逻辑运算符诸如放大器;&放大器;, ||确认了很多条件,那么code尺寸变使用多个嵌套的if语句时小。是否有任何其他利益(运行时,调试,编译时间效益等)if语句使用这种有条件运营商?
When using a logical operator such as &&, || to confirm a lot of conditions, then code size becomes smaller than when using multiple nested if statements. Is there any other benefit (run time, debugging, compile time benefit etc.) of using this if statement with conditional operator?
推荐答案
一个功能,你需要考虑,而作出决定是的短路评价
One feature you need to consider while making the decision is Short-circuit evaluation
这意味着当您使用条件运算符在嵌套if语句的第二个参数时,才会执行或评价,如果第一个参数不足以确定前pression的价值。
That means when you use conditional operators over nested if statements the second argument is only executed or evaluated if the first argument does not suffice to determine the value of the expression.
这篇关于有没有使用if语句逻辑运算符的任何好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!