![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
You might think that it would be possible to use a doulbe-ampersand
expression instead of an if
statement by exploiting the property
that the right-side operand of an double-ampersand expression is evaluated
only if the value of the left-side operand is true
.
You cannot do so, however, because both the operands surrounding &&
and ||
operators must be Boolean expressions.
Do not think that this requirement is a handicap. Most good programmers
object to the use of &&
and ||
operators to allow or
prevent evaluation. They argue that, when an &&
or ||
operator is included in an expression, anyone (other than the original
programmer) who looks at the expression, naturally expects the value
produced by the expression to be used. If the value is not used, the
person who looks at the program may wonder whether the original programmer
left out a portion of the program unintentionally.