MATLAB: Is the logical & operator in MATLAB a short circuit operator

MATLAB

Is the logical & operator in MATLAB a short circuit operator such that if the first argument is false, the second argument is not evaluated? Are the arguments evaluated in the order they appear ?

Best Answer

As of MATLAB 5.3 (R11), the logical & operator does not evaluate the second argument if the first is false; ie the operation is short circuited. The arguments are also evaluated in the order they are given. This is also the case for the logical | (OR) operator.
Please note however, that this is only true in IF and WHILE statements. For example, in the following code:
y = 0 & launch(1);
launch will be called. But if you do the following instead:
if (0 & launch(1)), end
launch will not be evaluated.