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.1OperatorsUse operators to calculate values, compare them, combine conditions, and work with bits.Bitwise operatorsShort circuit evaluationCore20 min5 exercises
  2. 3.2ConditionalsUse if and switch to make a program choose what to do.switchCore18 min4 exercises
  3. 3.3Loops and Jump StatementsUse for, while, and do-while loops, and trace when each loop stops.LoopsCore17 min4 exercises