An expression can include relational operators
(such as <
or ==
) and logical
operators (such as &&
, ||
,
or ~
). Use the logical operators and
and or
to
create compound expressions. MATLAB® evaluates compound expressions
from left to right, adhering to operator precedence rules.
Within the conditional expression of a while...end
block,
logical operators &
and |
behave
as short-circuit operators. This behavior is the same as &&
and ||
,
respectively. Since &&
and ||
consistently
short-circuit in conditional expressions and statements, it is good
practice to use &&
and ||
instead
of &
and |
within the expression.
For example,
The first part of the expression evaluates to false. Therefore, MATLAB does
not need to evaluate the second part of the expression, which would
result in an undefined function error.