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

Need to continue a for loop

Status
Not open for further replies.

WorkerBeeJ

Programmer
Aug 6, 2002
34
US
I'm new to VBScript so it's probably just a simple statement, but I need a way to skip to the next iteration of a for loop from the middle of the loop and can't find how to do it. Is this possible without having to put the rest of the code of the loop in an if or some similar statement? The code's pretty messy the way it is and I'd rather not have to nest it one more time.

Thanks in advance!
Jen
 
Jen,

If you code it correctly, you should have to jump from the middle of the FOR loop. Anyways, you can't have a NEXT in the middle of a FOR loop.

Can you show your code?

fengshui_1998
 
There are actually many occasions where one would want to jump to the next iteration of a loop. That's why in Java, there's a "continue" statement.

What I'm doing is processing a very lengthy list of addresses (200,000+). Several of these addresses don't have house numbers and some (but not all, or I'd just put it right in the SQL query) of those without house numbers can be skipped. All the rest need to be processed. Here is the pseudocode for what I need to do:

FOR curAddress = 1 TO rs.PageCount
bNum = rs.Fields("BuildingNum")

IF IsNull(buildingNum) AND other stuff is true THEN
' Here's where it would be simpler
' to just say continue rather than
' put the rest in an else block
END IF

'process the rest of the addresses
NEXT

Any suggestions?

Thanks.

 
WorkerBeej,

Actually, I would do the reverse of what is TRUE.

FOR curAddress = 1 TO rs.PageCount
bNum = rs.Fields("BuildingNum")

IF NOT IsNull(buildingNum) AND other stuff is FALSE THEN
'process the rest of the addresses
' Code here
' Code here
END IF

' This is what should be ignored
' Here's where it would be simpler
' to just say continue rather than
' put the rest in an else block
NEXT

fengshui_1998
 
Yes, that would work, but what I'm looking for is the equivalent to the java "continue". If I reverse the if statement, the address processing still needs to be in an if block, which is exactly what I'm trying to avoid.

Thanks.
 
Correction. Exit Do instead of Exit loop.
If you want "extra" protection in case you forget the Exit Do before the Loop then use
Loop While(0 = 1)

For I = 0 to J
Do
.......
if not IsObject(ary(I)) then exit do ' continue
.......
Exit Do ' continue
Loop While(0 = 1)
Next
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top