Todos los libros

Profesional

Apps Acerca de Coach Iniciar sesión Empezar a leer

Computer Science · Glosario

¿Qué es Short-circuit evaluation?

Definition 1.8 High School Computer Science · Capítulo 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.

Leer en el capítulo →
Definition 2.6 University Computer Science — Year 1 · Capítulo 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.
Leer en el capítulo →