ConditionOneOutEdge
DRAFT

Misconception:

A (diamond) condition node in a control-flow graph (especially for an if statement without an else) can have just one outgoing edge.

Incorrect

A condition node in a control-flow graph can have a single outgoing edge

Correct

Correction
Here is what's right.

A condition node in a CFG is a decision point: the next node to go to depends on the value of the condition. In general, the condition node has at least two outgoing edges.

For an if statement, even for an if statement without an else clause, the condition node has exactly two outgoing edges:

a();
if (cond) {
  b();
}
c();

In the above if statement, which has no else clause, the cond node is a diamond with two arrows: the “True” arrow points to b(), the “False” arrow points to c().

Note: In theory, there could be a conditional statement where the condition is guaranteed to always evaluate to the same value (e.g., while (true) {...}). In such cases, one could theoretically just draw the one feasible arrow, and leave the other one out. This would lead to a condition node with only one outgoing edge. However, this usually is not done, and one conservatively assumes that a condition’s value is not statically known.

Language

Java
Notional Machine
ControlFlowAsGraph

Concepts

Expressible In

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.