Syntax: "Exit Sub" or "Return" in VB.NET subroutines

Jeff picture Jeff · Jun 17, 2009 · Viewed 70.8k times · Source

Both "Exit Sub" or "Return" seem to accomplish the same thing -- exit a subroutine. Is there any difference in how they work under the covers?

That is,

Private Sub exitNow()
    Exit Sub
End Sub

or

Private Sub exitNow()
    Return
End Sub

Answer

RBarryYoung picture RBarryYoung · Jun 17, 2009

From the doc:

In a Sub or Set procedure, the Return statement is equivalent to an Exit Sub or Exit Property statement, and expression must not be supplied.

So they're the same in this context.

(Return (<value>) is used in functions and property.get's. Obviously slightly different in that context).