Logical Operations Short-circuiting
Short-circuit is exhibited by logical expressions containing &&
(AND) and || (OR) operators.
In a logical expression involving the && operator, if the
left-hand side expression evaluates to false, the overall expression
also evaluates to false. In this case, the right-hand side expression
is not evaluated because the outcome is already determined by the left-hand side
expression.
Similarly, for a logical expression involving the || operator, if
the left-hand side expression evaluates to true, the right-hand side
expression is not evaluated because the outcome is determined by the left-hand side
expression. This short-circuit evaluation of logical expressions helps you to optimize
the execution by avoiding unnecessary evaluations when the result is already
determined.
Short-circuiting Behavior for Condition and MCDC Objectives
Logical Operators and Logical Expressions for Condition and
MCDC objectives can be considered short-circuiting or not
when you analyze for dead logic or generate tests. The table summarizes different
considerations:
Short-circuit consideration for Condition and
MCDC objectives:
| Modeling element | Short-circuit consideration for
Condition and MCDC
Objectives |
|---|---|
Logic blocks (standalone/cascaded) |
|
Enabled subsystem |
|
| Triggered subsystem |
|
| Enabled and Triggered subsystem |
|
MATLAB®, Stateflow® (C or MATLAB as action language) and other Simulink® Blocks (Fcn, If) |
|
Short-circuiting Behavior for Condition Objectives
The table summarizes the difference between Condition
objectives that depend on CovLogicBlockShortCircuit
parameter:
Short-circuit considerations for Condition objectives
based on CovLogicBlockShortCircuit parameter
| Block | Condition
Objective
| Condition Expression when
CovLogicBlockShortCircuit is
ON | Condition Expression when
CovLogicBlockShortCircuit is
OFF |
|---|---|---|---|
Logical |
| (in1 && ~in2) | (~in2) |
Logical |
| (~in1 && ~in2) | (~in2) |
MATLAB Function or Chart containing expression (u1 && u2 && u3) | 'u2' | (u1 && ~u2) | (u1 && ~u2) |
Short-circuiting Behavior for MCDC Objectives
The table summarizes the difference in objectives that vary based on the
CovLogicBlockShortCircuit parameter as shown:
Short-Circuit considerations for MCDC objectives based on
CovLogicBlockShortCircuit parameter:
| Block | MCDC Objective | MCDCExpression when
CovLogicBlockShortCircuit is ON | MCDC Expression when
CovLogicBlockShortCircuit is OFF |
|---|---|---|---|
Logical | expression for output with input port 2
| (in1 && ~in2) | (in1 && ~in2 && in3) |
expression for output with input port 2
| (in1 && in2 && in3) | (in1 && in2 && in3) | |
MATLAB Function or Chart containing expression (u1 && u2 && u3) | expression for output with input port 2
| (in1 && ~in2) | (in1 && ~in2) |
expression for output with input port 2
| (in1 && in2 && in3) | (in1 && in2 && in2) |
Note
When MCDC expression is derived from a cascaded logic,
it follows similar definition as logic blocks.
For more information, see "Short-Circuiting of Boolean Expressions for MCDC" in Analyzing MCDC for Cascaded Logic Blocks (Simulink Coverage).
Impact of CovLogicBlockShortCircuit parameter on Condition and MCDC Results
In some cases, coverage result for MCDC objectives can vary
based on the CovLogicBlockShortCircuit parameter as shown:
When CovLogicBlockShortCircuit parameter is OFF, all the inputs
are considered.

Short-Circuit considerations for Condition objectives
based on CovLogicBlockShortCircuit parameter:
| Block | Condition Objective | Condition Expression when
CovLogicBlockShortCircuit is ON | Condition Expression when
CovLogicBlockShortCircuit is OFF |
|---|---|---|---|
Logical |
| (in1 && in2 && ~in2) (Dead Logic) | (~in2) (Active Logic) |
Short-Circuit considerations for MCDC objectives based on
CovLogicBlockShortCircuit parameter:
| Block | MCDC Objective | MCDCExpression when
CovLogicBlockShortCircuit is ON | MCDC Expression when
CovLogicBlockShortCircuit is OFF |
|---|---|---|---|
Logical | Expression for output with input port 2
| (in1 && ~in2) (Active Logic) | (in1 && ~in2 && in2) (Dead Logic) |