Name
GoTo Statement
Syntax
GoTo label-
label(required) Type: String literal
A subroutine name
Description
Passes execution to a specified line within a procedure
Rules at a Glance
label must be a line label
Programming Tips and Gotchas
GoTocan branch only to lines within the procedure where it appears.It is not permitted to branch from outside a
Try...Catch...Finallyblock to a point inside theCatchorFinallyblock.It is also not permitted to branch from within the
CatchorFinallyblock to a label outside the block.The
GoTostatement is most commonly used with theOnErrorstatement to direct control to an error-handling routine.GoTois frequently used to control program flow within a procedure, a technique that often produces highly unreadable “spaghetti code.” Accordingly, great care should be taken when using theGoTostatement.
VB.NET/VB 6 Differences
In VB 6, label could be either a line
number or a label. In VB.NET, label can be
only a label.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access