P
Phil...
My book says the following about && and ||
(see below dashed line.) And I wonder if this
is built into the language or an artifact of the
compiler. Previously (in my youth) we were
taught that depending on the compiler to skip
evaluating stuff was dangerous and bad for
maintenance.
----------------------------
known as the short-circuit logical operators:
&& short-circuit AND
|| short-circuit OR
The short-circuit feature of the && operator is that it doesn't waste its
time on
pointless evaluations. A short-circuit && evaluates the left side of the
operation first
(operand one), and if operand one resolves to false, the && operator doesn't
bother
looking at the right side of the equation (operand two). The operator
already knows
that the complete expression can't possibly be true, since one operand has
already
proven to be false.
(see below dashed line.) And I wonder if this
is built into the language or an artifact of the
compiler. Previously (in my youth) we were
taught that depending on the compiler to skip
evaluating stuff was dangerous and bad for
maintenance.
----------------------------
known as the short-circuit logical operators:
&& short-circuit AND
|| short-circuit OR
The short-circuit feature of the && operator is that it doesn't waste its
time on
pointless evaluations. A short-circuit && evaluates the left side of the
operation first
(operand one), and if operand one resolves to false, the && operator doesn't
bother
looking at the right side of the equation (operand two). The operator
already knows
that the complete expression can't possibly be true, since one operand has
already
proven to be false.