VBC09313 — Exit For not within For...Next
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
An Exit For statement is not lexically inside a For or a For Each loop.
MS-VBAL §5.4.2.5 Exit For Statement
requires it to be inside a For or a For Each statement, at any depth; MS-VBA reports the same error:
Exit For not within For...Next.
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 For 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 For loops. |
Do ... Exit For ... Loop |
Use Exit Do to leave a Do loop. |
It is in a While...Wend loop. |
While x ... Exit For ... Wend |
While...Wend has no Exit statement. Use a Do While loop. |
See also
⏮️ VBC09312 Exit Do not within Do...Loop | ⏭️ VBC09314 Exit Function not allowed in Sub or Property
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca