Equivalent VB keyword for 'break'

vb.netLoopsVb6Exit

vb.net Problem Overview


I just moved over to the Visual Basic team here at work.

What is the equivalent keyword to break in Visual Basic, that is, to exit a loop early but not the method?

vb.net Solutions


Solution 1 - vb.net

In both Visual Basic 6.0 and VB.NET you would use:

  • Exit For to break from For loop
  • Wend to break from While loop
  • Exit Do to break from Do loop

depending on the loop type. See Exit Statements for more details.

Solution 2 - vb.net

In case you're inside a Sub of Function and you want to exit it, you can use :

Exit Sub

or

Exit Function 

Solution 3 - vb.net

Exit [construct], and intelisense will tell you which one(s) are valid in a particular place.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTyronomoView Question on Stackoverflow
Solution 1 - vb.netJohnView Answer on Stackoverflow
Solution 2 - vb.netAyman El TemsahiView Answer on Stackoverflow
Solution 3 - vb.netEric HaskinsView Answer on Stackoverflow