【问题标题】:Does Go execute all the conditions in "if' if the first fails? [duplicate]如果第一个失败,Go会执行“if”中的所有条件吗? [重复]
【发布时间】:2021-01-22 08:57:52
【问题描述】:

想象下面这段代码:

if someBool && funcReturningABool() {
    // code here...
}

其中someBool 是布尔值,funcReturningABool 返回真或假。

如果someBool等于false,funcReturningABool还会被执行吗?

【问题讨论】:

  • 不,不会执行。

标签: go if-statement execution


【解决方案1】:

你可以在the Golang documentation找到:

有条件地计算右操作数

【讨论】:

    【解决方案2】:

    不会,而且不仅适用于golang。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多