Table of Contents

5.4.2.7 Exit Do Statement

Note

This section describes the implementation of MS-VBAL §5.4.2.7 Exit Do Statement.

Syntax

AST node Instruction kind(s) Notes
KeywordStatementNode (Token: "Exit Do") ExitLoop Target: the offset right past the closer of the innermost enclosing Do loop.

See RD-VBAL §3.4.2 Simple Statements and RD-VBAL §3.5.2 Instruction.

Static Semantics

Exit Do needs an enclosing loop of one of the five Do…Loop forms (RD-VBAL §5.4.2.6 Do Statement). It resolves against the innermost enclosing loop of that kind.

A While…Wend loop does not satisfy Exit Do: MS-VBAL gives While…Wend no exit statement of its own (RD-VBAL §5.4.2.2 While Statement). An Exit Do written inside a While…Wend is not consumed by it; it resolves against the Do loop that encloses the While…Wend.

An Exit Do that has no enclosing Do loop, including one inside a While…Wend that no Do loop encloses, is VBC09312 (ExitDoNotWithinDoLoop). The rule is ExitStatementStaticSemantics's, which StatementStaticSemanticsEvaluator and instruction-list lowering both ask. Lowering emits no instruction for the statement that is an error.

Runtime Semantics

  1. ExitLoop branches to Instruction.Target, in the same way as Jump (RD-VBAL §5.4.2.12 GoTo Statement).
  2. No runtime search is needed: lowering has already resolved Target to the offset right past the innermost enclosing loop of the matching kind.

Implementation


⏮️ RD-VBAL §5.4.2.6 Do Statement | ⏭️ RD-VBAL §5.4.2.8 If Statement