MATLAB Function Reference 
Logical operations, with shortcircuiting capability
Syntax
Description
The symbols &&
and 
are the logical AND
and OR
operators used to evaluate logical expressions. Use &&
and 
in the evaluation of compound expressions of the form
where expression_1
and expression_2
each evaluate to a scalar logical result.
The &&
and 
operators support shortcircuiting. This means that the second operand is evaluated only when the result is not fully determined by the first operand. See ShortCircuit Operators in the MATLAB documentation for a discussion on shortcircuiting with &&
and 
.
Note
Always use the && and  operators when shortcircuiting is required. Using the elementwise operators (& and  ) for shortcircuiting can yield unexpected results.

Examples
In the following statement, it doesn't make sense to evaluate the relation on the right if the divisor, b
, is zero. The test on the left is put in to avoid generating a warning under these circumstances:
By definition, if any operands of an AND
expression are false
, the entire expression must be false
. So, if (b ~= 0)
evaluates to false
, MATLAB assumes the entire expression to be false
and terminates its evaluation of the expression early. This avoids the warning that would be generated if MATLAB were to evaluate the operand on the right.
See Also
all
, any
, find
, logical
, xor
, true
, false
Logical operators, elementwise, &
, 
, ~
Relational operators <
, <=
, >
, >=
, ==
, ~=
Logical Operators: Elementwise &  ~  loglog 
© 19942005 The MathWorks, Inc.