Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VB.NET is "Exit Sub" necessary or helpful?

When using Sub's, if I'm not returning a value, is it necessary to use:

Public Sub whatever()
       ...
       Exit Sub
End Sub

instead of just

Public Sub whatever()
       ...
End Sub

Do I gain anything (memory, speed, etc.) by using "Exit"?

Does the Sub exit anyway when it is done even if I don't use the "Exit" statement?

Thanks.

like image 897
John Avatar asked Dec 09 '22 13:12

John


1 Answers

In this particular case Exit Sub is completely unnecessary. It can be used there but is generally considered bad style. The statement is necessary when you want to prematurely leave the method. For example if you detect a specific condition is met and you don't want to execute the rest of the method

Public Sub Example() 
  If SomeCondition Then 
    Exit Sub
  End If

  ' Do other work
End Sub
like image 172
JaredPar Avatar answered Dec 11 '22 12:12

JaredPar