v4 Semantics: loop rules and scope
Lesson, slides, and applied problem sets.
View SlidesLesson
v4 Semantics: loop rules and scope
New rules
break / continue
breakandcontinueare only valid inside loops.
for loop scope
- A
forloop creates a new scope for itsinit. - Variables declared in
initare 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
loopDepthcounter. - When you enter a
fororwhile, increment it. - When you leave, decrement it.
Keep it straightforward and predictable.