有没有使用if语句逻辑运算符的任何好处? [英] Is there any benefit of using if statement with logical operator?

查看:272
本文介绍了有没有使用if语句逻辑运算符的任何好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆