全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Short-circuit evaluation?

Definition 1.8 High School Computer Science · 第 1 章 — Specifications, Assertions and Tests

Python evaluates a and b by evaluating a first; if a is false, the result is false and b is not evaluated at all. It evaluates a or b by evaluating a first; if a is true, the result is true and b is not evaluated. This is short-circuit evaluation.

在原文中阅读 →
Definition 2.6 University Computer Science — Year 1 · 第 2 章 — C: Types, Operators and Control Flow

In a && b and a || b, the operand a is evaluated first; b is evaluated only when a does not already decide the result (a true for &&, false for ||). This is short-circuit evaluation. A test such as n != 0 && 10 / n > 1 relies on it to avoid dividing by zero.

The tree of a + b * c > d && e != 0: * binds tighter than +, which binds tighter than >, and && is loosest. The left subtree of && is evaluated first, and the right one only if the left is true.
The tree of a + b * c > d && e != 0: * binds tighter than +, which binds tighter than >, and && is loosest. The left subtree of && is evaluated first, and the right one only if the left is true.
在原文中阅读 →