Table of Contents

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

  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.4 For Each Statement | ⏭️ RD-VBAL §5.4.2.6 Do Statement