Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return to Top

Status
Not open for further replies.

mclellan

Programmer
Aug 6, 2002
294
CA
Is there a way in VB.NET to return to the top of your for loop?

for x = 1 to 10

if x = 2 then [** go to the top of the loop and skip code underneath **]

do stuff here

next

Thanks
Barry
 
Code:
Do ..

For...
...
IF x = 2 then exit for

do stuff here

Next

Loop until ?

As long as your logic avoids a continuous loop i.e. you need an exit point for the outer loop. You also need to decide how the outer loop handles (x never = 2).
 
Hi techsmith,

Sorry, it wasn't really about the if/then/else structure, I just wanted to know how to bypass all your code and jump to the top of the loop.

I belive C++ and Java have a 'continue' statement, but I can't find one in VB.NET.
 
'Exit For' is the equivalent of continue i.e. jump to the next item in the For...Next iteration and skip remaining code in For Next block for current item.

I added the outer loop as I misunderstood your question thinking that you wanted to re-start the For...Next loop when a condition is met.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top