我在一个紧密循环中有一个 switch 语句,如下所示:
switch(true) {
case /*expensive comparison */:
case /*another expensive comparison */:
case /*different expensive comparison */:
return true;
}
return false;
我想看看是否有任何昂贵的比较是真的,但只有一个。我知道还有其他方法可以做到这一点,但这个看起来很干净。真正的问题是:如果expensive comparison
计算结果为真,它是否也运行another expensive comparison
,或者只是跳转到返回?
编辑: 我意识到这可以通过一个简单的 or 语句来完成,但现在我想知道理论上的缘故。
return /*expensive comparison */
|| /*another expensive comparison */
|| /*different expensive comparison */;