Layers of Logic

Phase III

Logic and Flow

Making a program compute, decide, and repeat.

3 sections55 min of reading13 exercises

Operators compute values, branches select work, and loops repeat it. This phase traces the exact evaluation rules behind each one. It covers division toward zero, signed remainder, compound assignment, short-circuit order, fixed-width shifts, boolean branch conditions, switch statements and expressions, loop invariants, and off-by-one boundaries.

When you finish this phase you can

  • Predict integer division and remainder, including negative operands, from the truncation rule and identity
  • Explain the implicit cast and single left-side evaluation in compound assignment
  • Predict overflow, shift-distance masking, sign extension and zero filling
  • Write boolean branches with explicit braces and ordered conditions
  • Distinguish a switch statement from a switch expression and use yield in a block arm
  • Trace for, while and do-while execution and state an invariant and stopping condition
  1. 3.1OperatorsCalculate values, compare them, short-circuit boolean expressions, and manipulate fixed-width bit patterns.Bitwise operatorsShort circuit evaluationCore20 min5 exercises
  2. 3.2ConditionalsBoolean branches, braces, ordered tests, and switch statements and expressions without hidden fallthrough.switchCore18 min4 exercises
  3. 3.3Loops and Jump StatementsChoose a loop from its condition, trace its execution order, and prove that each pass makes progress toward stopping.LoopsCore17 min4 exercises