Table of Contents

VBC09312 — Exit Do not within Do...Loop

Severity: Error  ·  Family: VBC (static semantics / abstract syntax tree)  ·  Source metadata: VBCompileErrorInfo

An Exit Do statement is not lexically inside a Do loop.

MS-VBAL §5.4.2.7 Exit Do Statement requires it to be inside a Do statement, at any depth; MS-VBA reports the same error: Exit Do not within Do...Loop.

This code is raised by ExitStatementStaticSemantics, which StatementStaticSemanticsEvaluator and instruction-list lowering (InstructionListLowering) both ask.

How it is raised

Situation Example Resolution
There is no loop around the statement. Exit Do in the body of a Sub Remove it, or use Exit Sub, Exit Function or Exit Property to leave the procedure.
The loops around it are not Do loops. For i = 1 To 3 ... Exit Do ... Next Use Exit For to leave a For loop.
It is in a While...Wend loop. While x ... Exit Do ... Wend While...Wend has no Exit statement. Use a Do While loop.

Notes

An Exit Do is the closest enclosing Do loop's, so an Exit Do in a Do loop that is inside a For loop is valid, and so is an Exit For in a Do loop that is inside a For loop.

See also


⏮️ VBC09309 Label not defined | ⏭️ VBC09313 Exit For not within For...Next


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca