Table of Contents

5.4.2.12 GoTo Statement

Note

This section describes the implementation of MS-VBAL §5.4.2.12 GoTo Statement.

Syntax

AST node Instruction kind Notes
GoToStatementNode Jump Instruction.Target holds the offset of the target label.

A GoTo statement's target is an expression naming or numbering a label or line. There is no static link between the GoToStatementNode and the LineLabelNode or LineNumberNode it targets (RD-VBAL §3.4.2 Simple Statements).

A bare line-number target in a single-line If branch (If x Then 100) is not modelled as its own shape. The parser synthesizes a GoToStatementNode as that branch's statement, typically its only one (RD-VBAL §5.4.2.9 Single-line If Statement).

GoTo lowers to the InstructionKind Jump (RD-VBAL §3.5.2 Instruction).

Static Semantics

Lowering resolves the target label to an offset (RD-VBAL §3.5.3 Lowering Block Statements). A label is scoped to the whole procedure, so a GoTo from anywhere in the procedure into the middle of a loop body or an If body resolves in the same way as any other jump (RD-VBAL §5.4.1.1 Statement Labels).

Condition Result
The procedure defines the target label. Target is the label's offset.
The procedure does not define the target label, e.g. GoTo Done with no Done: line. Target is null, and lowering reports VBC09309 Label not defined.

Runtime Semantics

  1. The executor dispatches a Jump instruction as an unconditional GoTo: execution branches to Instruction.Target, the offset of the target label.
  2. A label with no statement after it, including the end-label of the lexically enclosing procedure declaration, resolves to the offset right past the last instruction. A branch to it completes the activation as if execution had reached the end of the procedure body (RD-VBAL §3.5.1 InstructionList).

An instruction's EnclosingWith is computed once, at lowering time; it is not tracked as a runtime stack the interpreter pushes and pops. A GoTo into or out of a With block therefore leaves no stale state to unwind (RD-VBAL §5.4.2.21 With Statement).

A GoTo that lands directly on the Next of a For or For Each loop whose opener has not run in the activation raises run-time error 92, "For loop not initialized"; see RD-VBAL §5.4.2.3 For Statement and RD-VBAL §5.4.2.4 For Each Statement.

Implementation


⏮️ RD-VBAL §5.4.2.11 Stop Statement | ⏭️ RD-VBAL §5.4.2.13 On...GoTo Statement