Short-circuit operators
ID | CC-9 |
Title | Use short-circuit logical operators (&&, ||) only in conditional statements. |
Priority | Mandatory |
Severity level | 6 |
Description | Use short-circuit logical operators (&& , \|\| ) only in conditional statements. In other statements, you can use & or \| instead. |
Rationale | Compatibility, Completeness |
Avoid:
test1 = a > b;
test2 = b < a.^2;
result = test1 || test2;
Above will not work for vector values for a
and b
. Use elementwise logical operator |
instead.
Instead use:
result = test1 | test2;