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 may 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 &  ~  Special Characters [ ] ( ) {} = ' . ... , ; % ! 