v4 Control Flow: for, break/continue, && / ||
- Predict for-loop, break, and continue execution order.
- Separate runtime short-circuiting from static traversal.
- Extend maximal-munch lexing with logical operators and loop keywords.
1 / 6
let total=0;
for (let i=0; i<4; i=i+1) {
if (i==1) { continue; }
if (i==3) { break; }
total=total+i;
}
| i entering body | Body path | Post-step runs? | total |
|---|---|---|---|
| 0 | add 0 | yes | 0 |
| 1 | continue | yes | 0 |
| 2 | add 2 | yes | 2 |
| 3 | break | no | 2 |
Initialization runs once. The condition precedes every body entry. Continue jumps to post (or the condition if post is absent); break skips post and exits. The initializer's i is scoped to the loop and is unavailable afterward. The body is a nested block, so its local declarations do not become post-step locals.
A loop with continue at i=1 never terminates after a refactor. Another lexer accepts a single & as AND. Identify the execution-edge defect and lexical contract defect.
Modify the worked loop so post is absent and the body increments i explicitly. Identify where continue must go and how to keep the loop terminating. Tokenize continueFlag || false && true without deciding its runtime path.
Carry the event trace and new tokens into v4 parsing. Save separate tests for token boundaries, AST precedence, static loop legality, and runtime skip behavior.