5.4.2.5 Exit For Statement
Note
This section describes the implementation of MS-VBAL §5.4.2.5 Exit For Statement.
Syntax
| AST node | Instruction kind(s) | Notes |
|---|---|---|
KeywordStatementNode (Token: "Exit For") |
ExitLoop |
Target: the offset right past the closer of the innermost enclosing For or For Each loop. |
See RD-VBAL §3.4.2 Simple Statements and RD-VBAL §3.5.2 Instruction.
Static Semantics
Exit For needs an enclosing For or For Each loop
(RD-VBAL §5.4.2.3 For Statement,
RD-VBAL §5.4.2.4 For Each Statement). It resolves against the
innermost enclosing loop of that kind.
A While…Wend loop does not satisfy Exit For
(RD-VBAL §5.4.2.2 While Statement).
An Exit For that has no enclosing For or For Each loop is
VBC09313 (ExitForNotWithinForNext). The rule is
ExitStatementStaticSemantics's, which
StatementStaticSemanticsEvaluator and instruction-list
lowering both ask: the statement is lexically inside a loop of the kind, at any depth. Lowering emits no instruction for the statement that is an error.
Runtime Semantics
ExitLoopbranches to Instruction.Target, in the same way asJump(RD-VBAL §5.4.2.12 GoTo Statement).- No runtime search is needed: lowering has already resolved
Targetto the offset right past the innermost enclosing loop of the matching kind.
Implementation
- InstructionListLowering resolves the
ExitLooptarget (RD-VBAL §3.5.3 Lowering Block Statements). ProcedureExecutoruses the samecasearm forExitLoopandJump.
⏮️ RD-VBAL §5.4.2.4 For Each Statement | ⏭️ RD-VBAL §5.4.2.6 Do Statement