Control Flow as Graph
Represent execution paths through a method or function as a graph

This notional machine represents method bodies as graphs. Statements are represented as rectangles and conditions as diamonds.

This makes the possible execution paths through the different statements of a method visible and is particularly useful for explaining compound statements (loops and conditional statements), conditional expressions, and exception handling.

Notional Machine Collection

The notionalmachines.github.io web site contains more information about ControlFlowAsGraph.

30 Misconceptions Expressible in this Notional Machine

A notional machine focuses on a subset of the syntax and semantics of a programming language. The following misconceptions are related to the language features expressible in this notional machine.

Misconception
CatchAlwaysExecutes
Catch blocks always get executed
Misconception
CatchProvidesOptions
Only the necessary part of a catch block executes
Misconception
ConditionOneOutEdge
A condition node in a control-flow graph can have a single outgoing edge
Misconception
ConditionalIsSequence
If-else is equivalent to sequence of two ifs
Misconception
ConditionalIsSequence
If-then-else block is equivalent to sequence of two if-then blocks
Misconception
DeferredReturn
A return statement in the middle of a method doesn't return immediately
Misconception
DeferredReturn
A return statement in the middle of a function doesn't return immediately
Misconception
ElsIf
There is an elsif keyword for multi-way conditional statements
Misconception
ElseAlwaysExecutes
The else branch of an if-else statement always executes
Misconception
ElseAlwaysExecutes
The else branch of an if-then-else block always executes
Misconception
ForIsConditional
The body of a for statement executes at most once
Misconception
IfIsLoop
The body of an if statement executes repeatedly, as long as the condition holds
Misconception
IfIsLoop
The body of an if-statement executes repeatedly, as long as the condition holds
Misconception
IfRequiresElse
Every if statement requires an else
Misconception
InterproceduralEdge
In an intra-procedural control-flow graph, method call nodes point to the called method
Misconception
LoopTerminatingCondition
For and while loops end when the condition becomes true
Misconception
MissingElseTerminates
Blocks following an if without else will not execute if the condition is false
Misconception
NoShortCircuit
&& and || always evaluate both operands
Misconception
NoShortCircuit
and/or always evaluate both operands
Misconception
PreIncrementBeforeLoop
Pre-increment in update part of for loop means increment before loop body
Misconception
RecursiveCallSiteNoReturn
Tail-recursive call sites have no continuation
Misconception
RecursiveMethodNeedsIfElse
A recursive method needs to contain an if-else statement
Misconception
RepeatDistributes
Each block in a loop is repeated individually
Misconception
ResetStateEachLoopIteration
The computation of all loop iterations starts from the state before the loop
Misconception
ReturnNoOutEdge
In a control-flow graph, a return statement has no outgoing edge
Misconception
StatementMultipleOutEdges
A non-condition node in a control-flow graph can have multiple outgoing edges
Misconception
SuperNotFirstStatement
super() can be called anywhere in the constructor of a subclass
Misconception
TryFinishes
Exceptions get thrown at the end of the try block
Misconception
ZeroInEdges
A control-flow graph node (other than the entry node) can have zero incoming edges
Misconception
ZeroOutEdges
A control-flow graph node (other than the exit node) can have zero outgoing edges

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.