break statement

Joined
Mar 28, 2005
Messages
17
Programming Experience
Beginner
Hi everyone,

In Java, when you want to break out of an if statement or for loop, you use the 'break' statement. Is there a similar one for VB?

Thanks,
Kevin
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
in the code window click the grey area on the left side of the section where you type the code in, a red dot will appear in the grey area and then the line of text to break from will also be highlighted in red, to turn it off click the red dot and it'll dissappear

you can set break points both at design time and run time
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
i personally try to avoid using exit statements as it creates more confusion when you complete a project then you set it aside for a year or two and when you go back to it to update it or whatnot things are already confusing enough

if you dont know when exactly the loop will need to exit or if you're checking for a condition that will require the loop to terminate early i wouldnt use a for...next loop in the first place a do while or a loop until loop would be much more appropriate
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,331
Location
Sydney, Australia
Programming Experience
10+
Equivalent to "continue" from C++

Using Exit For in VB is exactly the same as using break in Java or other C-style languages. What I really miss, having done some C++ development in the past, is an equivalent to continue. The only alternative I have been able to come up with is to enclose the remainder of the loop's code in an If block using the opposite condition than I would if using continue. This is not a big deal but I'd rather have my code within as few blocks as possible.
 
Top Bottom