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

continue and break statement helps please 1

Status
Not open for further replies.

TWillard

Programmer
Apr 26, 2001
263
US
I am working on a block of code that contains an outer loop and an inner loop. Within both loop statements, I have several if/else conditions. Is it possible for me to use breaks and continue statements on the outer loop, even if I am currently within an if condition that is within the inner loop?

I have learned that ASP provides a both a break and continue statement. However, what I am really looking for is something similar to break labels. I have used break labels many times in JavaScript and Java. Can you help me please?

 
Sorry for the errors!!!! 'helps', 'provides a both a '

I was typing in a hurry.
 
dim breakOuter
do while someValue < someSentinel
breakOuter = false
do while someOtherValue < someOtherSentinel
if someCondition then
breakOuter = true
exit do
end if

'the rest of your inner logic here

someOtherSentinel = someOtherSentinel + 1
loop
if breakOuter then
exit do
end if

'the rest of your outer logic here

someSentinel = someSentinel + 1
loop

I think will be about the best you're going to be able to muster in vbScript. You'll only be able to exit one loop at a time, but then set some flag value that you immediately check upon exiting to see if you need to get out of that one, too.

hope that helps! :)
paul
penny.gif
penny.gif
 
link9,

Thank you for answering my question. Your answer provides insight into controlling looping structures. Although I don't quite understand why vbscript does not include something as elegant as a break statement.

Just want to let you know that I have read many of your posts. Your participation in tek-tips is greatly appreciated.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top