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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on going back to the beginning of a do...while loop midway.

Status
Not open for further replies.

inahs2k

Programmer
Jul 25, 2003
12
US
Hi everybody,

I have a strage problem. I have a Do...While loop. I was wondering if there is anything in VBA similar to the CONTINUE instruction in JAVA or C++ so that I can go back to the beginning of the Do loop midway through the loop without executing the rest of the code based on some test. To make it clear,

Do While Not recordSet.EOF
'Some code here...........
'Some calculations here......
If someVariable = 0 Then
'This is where I want to go back to the beginning _
of the Do Loop without going through the rest of _
the code in the loop.
End If
'Some other code here onwards.
Loop

In JAVA or C++, I could have said CONTINUE and I can go back to the beginning of the loop. Is there anything similar to that in VBA?? Any help or pointers will be greatly appreciated.

Thanks a lot in advance.
Have a great weekend.
Shahnaz.
 
why not just put an if/else statment like you have....If you want the to go back to the beginning of the loop when a conditon is met have the if statment like you have it, and put the rest of the coding in the else part of the statement. This way the coding will be skipped if the condition is met.
 
CONTINUE is almost as controversial as GOTO in terms of whether it is considered bad programming practice.

See thread707-471299

My recommendation is still that you would be better off to use a different structure to make the code easier to maintain later.
 
Thanks guys, I think I will use the If/Else structure after all as suggested by Jooky68. I also agree with Zathras about programming practice.

Thanks once again.
Shahnaz.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top