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

While Wend vs. Do While Loop

Status
Not open for further replies.

Spork52

Programmer
Nov 20, 2007
134
0
0
US
Am I correct that vbScript does not have a command for exiting a While Wend loop? Should I use a Do While Loop instead if I want to have an exit condition? Is there any functional difference that I should be aware of?

I'm looping through record sets like this:

Code:
While NOT rsSomeData.EOF
. . . do some stuff . . . 
rsSomeData.MoveNext
Wend

I don't want to force an exit in the While Wend by using rsSomeData.MoveLast because I'm not sure if that will work in all circumstances without generating errors--I'm assuming it's dependent on what kind of cursor is being used.

Will this

Code:
Do While NOT rsSomeData.EOF
if somecondition then
exit do
end if
. . . do some stuff . . . 
rsSomeData.MoveNext
Loop

accomplish the same thing without surprises?
 
Code:
Do While NOT rsSomeData.EOF
if somecondition then
exit do
end if
. . . do some stuff . . . 
rsSomeData.MoveNext
Loop

^ Did you test that?

You could also put the somecondition in the loop condition

Code:
Do while not rs.eof or not somecondition

... do some stuff ...

Loop



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
to answer your question directly: the difference between do while and while wend is verbage.

they are identical although the usage is sligtly different but fully interchangeable.

and lastly to specifically answer the exit question: it's the same for both exit loop.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top