Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent VB keyword for 'break'

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?

like image 975
Tyronomo Avatar asked Aug 08 '08 07:08

Tyronomo


People also ask

How do you break a loop in VB?

In VB.NET, the Exit statement is used to terminate the loop (for, while, do, select case, etc.) or exit the loop and pass control immediately to the next statement of the termination loop.

How do you break out of a sub in VB?

In a Sub procedure, the Exit Sub statement is equivalent to the Return statement. Immediately exits the Try or Catch block in which it appears. Execution continues with the Finally block if there is one, or with the statement following the End Try statement otherwise.

What is use of exit statement in Visual Basic?

The Exit statement transfers the control from a procedure or block immediately to the statement following the procedure call or the block definition. It terminates the loop, procedure, try block or the select block from where it is called.

What is a For loop in Visual Basic?

A For Next loop is used to repeatedly execute a sequence of code or a block of code until a given condition is satisfied. A For loop is useful in such a case when we know how many times a block of code has to be executed. In VB.NET, the For loop is also known as For Next Loop.


1 Answers

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.

like image 114
John Avatar answered Nov 15 '22 12:11

John