ReturnNoOutEdge
DRAFT

Misconception:

A rectangle representing a return statement in a control-flow graph represents the end of the execution and thus doesn’t have any outgoing edge.

Incorrect

In a control-flow graph, a return statement has no outgoing edge

Correct

Correction
Here is what's right.

In a control-flow graph we want to have a single entry node (where the execution must start) and a single exit node (where the execution must end).

Given that one can have multiple return statements in a method, we need to have an artificial exit node (usually a round node labeled “x”), and all return statements (or other statements that end execution of the method) have an outgoing edge to that exit node.

Note: This may not be an essential aspect for understanding how to represent control-flow with a CFG. The reason we want a single exit node is that we can run program analysis algorithms (the kind of algorithms a compiler or bug-finding tool would run over your program code) that perform their analysis in a backwards-fashion (from exit to entry node, in the opposite direction that a program execution would proceed). Given that in this course we don’t study program analysis algorithms, this “misconception” is not really that important.

Language

Java
Notional Machine
ControlFlowAsGraph

Concepts

Expressible In

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.