5.4.2.6 Do Statement
Note
This section describes the implementation of MS-VBAL §5.4.2.6 Do Statement.
Syntax
Do...Loop has five header shapes, each represented by its own node type.
| AST node | Instruction kind(s) | Notes |
|---|---|---|
| DoLoopStatementNode | Jump |
Bare Do … Loop. The back-edge Jump carries the loop's own node; its Target is the body's first instruction. |
| DoWhileLoopStatementNode | ConditionalBranch, Jump |
Pre-test Do While … Loop. The header's Else is right past the loop; a synthesized back-edge Jump (Node = null) targets the header. |
| DoUntilLoopStatementNode | ConditionalBranch, Jump |
Pre-test Do Until … Loop; the same shape as Do While. |
| DoLoopWhileStatementNode | LoopBack |
Post-test Do … Loop While. The LoopBack closer carries the loop's own node; its Target is the body's first instruction. |
| DoLoopUntilStatementNode | LoopBack |
Post-test Do … Loop Until; the same shape as Loop While. |
The …Until half of each pre-test and post-test pair shares its node shape with the …While half. Loop has no AST
node of its own (RD-VBAL §3.4.1 Block Statements;
RD-VBAL §3.5.2 Instruction).
Static Semantics
MS-VBAL models …While and …Until loops as the same construct with opposite exit polarity.
Exit Do resolves against the innermost enclosing loop of any of the five forms
(RD-VBAL §5.4.2.7 Exit Do Statement).
Runtime Semantics
| Form | Dispatch |
|---|---|
Pre-test: Do While, Do Until |
A ConditionalBranch, dispatched in the same way as an If header (RD-VBAL §5.4.2.8 If Statement). When the loop continues, execution falls through into the body; when it ends, it goes to the header's Else offset, right past the loop. |
Post-test: Do…Loop While, Do…Loop Until |
LoopBack: evaluate the condition; branch back to the body's first instruction (Instruction.Target) when the loop continues, and fall through when it ends. |
Bare: Do…Loop |
An unconditional Jump back to its own body. It needs no dispatch of its own. |
The condition of a pre-test or post-test loop is a Boolean condition, evaluated by the same ConditionEvaluator an
If uses, and forced to Boolean
(MS-VBAL §5.5.1.2.2 Let-coercion to and from Boolean).
| Loop | Exits when the condition is |
|---|---|
…While |
False |
…Until |
True |
For an …Until loop, the evaluated Boolean is inverted before branching.
Pre-test, post-test and bare Do loops need no per-activation state.
Implementation
ProcedureExecutordispatches the pre-test header'sConditionalBranch, the post-test closer'sLoopBack, and the bare loop'sJump.- A post-test loop's closer evaluates the condition and decides whether to branch back. The
LoopBackinstruction carries the loop's own node: it is the loop's only instruction (RD-VBAL §3.5.3 Lowering Block Statements). GetConditionreturns a(Condition, Negate)pair instead of a bare expression;Negateis true for an…Untilloop. The evaluated Boolean loop condition is inverted before branching whenNegateis true. The pair avoids duplicating the branch logic for a second polarity.RDCore.Runtime.Execution.ConditionEvaluatorforces the condition toBoolean(RD-VBAL §3.5.4 Execution).
⏮️ RD-VBAL §5.4.2.5 Exit For Statement | ⏭️ RD-VBAL §5.4.2.7 Exit Do Statement