Represent execution paths through a method or function as a graph
Control Flow as 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.
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.
CatchAlwaysExecutes
Catch blocks always get executedCatchProvidesOptions
Only the necessary part of a catch block executesConditionOneOutEdge
A condition node in a control-flow graph can have a single outgoing edgeConditionalIsSequence
If-else is equivalent to sequence of two ifsConditionalIsSequence
If-then-else block is equivalent to sequence of two if-then blocksDeferredReturn
A return statement in the middle of a method doesn't return immediatelyDeferredReturn
A return statement in the middle of a function doesn't return immediatelyElsIf
There is an elsif keyword for multi-way conditional statementsElseAlwaysExecutes
The else branch of an if-else statement always executesElseAlwaysExecutes
The else branch of an if-then-else block always executesForIsConditional
The body of a for statement executes at most onceIfIsLoop
The body of an if statement executes repeatedly, as long as the condition holdsIfIsLoop
The body of an if-statement executes repeatedly, as long as the condition holdsIfRequiresElse
Every if statement requires an elseInterproceduralEdge
In an intra-procedural control-flow graph, method call nodes point to the called methodLoopTerminatingCondition
For and while loops end when the condition becomes trueMissingElseTerminates
Blocks following an if without else will not execute if the condition is falseNoShortCircuit
&& and || always evaluate both operandsNoShortCircuit
and/or always evaluate both operandsPreIncrementBeforeLoop
Pre-increment in update part of for loop means increment before loop bodyRecursiveCallSiteNoReturn
Tail-recursive call sites have no continuationRecursiveMethodNeedsIfElse
A recursive method needs to contain an if-else statementRepeatDistributes
Each block in a loop is repeated individuallyResetStateEachLoopIteration
The computation of all loop iterations starts from the state before the loopReturnNoOutEdge
In a control-flow graph, a return statement has no outgoing edgeStatementMultipleOutEdges
A non-condition node in a control-flow graph can have multiple outgoing edgesSuperNotFirstStatement
super() can be called anywhere in the constructor of a subclassTryFinishes
Exceptions get thrown at the end of the try blockZeroInEdges
A control-flow graph node (other than the entry node) can have zero incoming edgesZeroOutEdges
A control-flow graph node (other than the exit node) can have zero outgoing edges