Chapter 7 · Simulation

Decision Tracer

← Chapter 7
Java code
    Flowchart

    Output (console)
    Variables

    Decision Tracer

    Purpose: see which branch of a conditional is chosen, and why. Each condition is shown in three steps: the expression → with the values substituted → true / false. The path taken is highlighted in both the code and the flowchart.

    How to use it

    1. Pick a program on the left and change the input variables (for example try the boundary values score = 59, 60, 61).
    2. Move on with Step ▶ / ◀ Back (keyboard → / ←), Play and Reset. The arrows and boxes the flow passes through are coloured in the flowchart.
    3. In conditions with logical operators, the small boxes below show the value of each part; the dashed, struck-through boxes are parts that were never evaluated because of short-circuiting.
    4. Try it yourself: predict the result of each condition and which case a switch jumps to.

    Reminders

    • In an else-if chain at most one branch runs; independent ifs are each tested separately.
    • Dangling else: an else binds to the nearest unmatched if, not to the indentation. Curly braces remove the ambiguity.
    • && does not evaluate the right side when the left is false, and || does not when the left is true (short-circuit). & and | always evaluate both sides.
    • In a classic switch, without break the code of the next case runs too (fall-through). The arrow form (->) has no fall-through (Java 14+).

    The output of every program was checked against real Java (JDK 21) output for every parameter combination.

    Related slides: Chapter 7 · Conditionals (if-else, else-if, nested decisions, dangling else, logical operators, switch).