v4 Semantics: loop rules and scope

Lesson, slides, and applied problem sets.

View Slides

Lesson

v4 Semantics: loop rules and scope

New rules

break / continue

  • break and continue are only valid inside loops.

for loop scope

  • A for loop creates a new scope for its init.
  • Variables declared in init are visible in the loop body and post.

logical operators

  • && / || do not add new static rules.
  • Both sides should still be analyzed (even though runtime short-circuits).

Implementation hints

  • Track a loopDepth counter.
  • When you enter a for or while, increment it.
  • When you leave, decrement it.

Keep it straightforward and predictable.


Module Items