Control Flow as Graph — 4. Short-Circuit

Control Flow as Graph is a sequence consisting of the following 5 notional machines:
1. Sequence
2. Selection
3. Multi-Way Selection
4. Short-Circuit
5. Repetition

Programming Language

imperative / Java

Form

Representation

Attribution — Origin / Source

Collected by Matthias Hauswirth — Compilers (control-flow graphs) and flow charts

Conceptual Advantage

Understand concept of short-circuit Boolean operators (|| and &&), and see how they only evaluate their right operand if needed.

Mapping

PLNM
... ...
|| in condition 'false' arrow to extra diamond node
&& in condition 'true' arrow to extra diamond node

Draws Attention To

The idea that for short-circuit Boolean operators, the second operand may never be evaluated (allowing common constructs like if (o!=null && o.length>0) ...

Use When

When introducing short-circuit operators && and ||

Cost

Requires prior introduction of 'Selection'.

Details

This is the fourth in a sequence of "Control Flow as Graph" notional machines:

  1. Sequence
  2. Selection
  3. Multi-Way Selection
  4. Short-Circuit
  5. Repetition

More Information

This notional machine is implemented by the Informa Clicker tool. This tool allows students in a classroom to construct control flow graphs in in-class clicker exercises.

Check this research paper

Matthias Hauswirth and Andrea Adamoli
Solve & Evaluate with Informa: A Java-based Classroom Response System for Teaching Java
PPPJ '09

Comments or Feedback?

Do you have feedback on this notional machine? Did you find a mistake, or do you have a request for improvement? You can create an Issue on GitHub, where the description is hosted. This way we can see your feedback and address it.

For this, you need a GitHub account. Then follow this link to see the source file of this page. In there, click the ... left of the highlighted line, then pick "Reference in a new issue".

Create an Issue on GitHub