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
 
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
 
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
 
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.
 
Back
Top