|
-
May 11th, 2001, 01:19 PM
#1
Do you know if VB has a similiar "continue" statement like in C?
Do you know if VB has a similiar "continue" statement? I want the statement to exit the current loop(i) then go into the next loop(i+1).
Thanks!
Best Regards,
Kevin Shen
Best Regards,
Kevin Shen
-
May 11th, 2001, 02:13 PM
#2
Re: Do you know if VB has a similiar "continue" statement like in C?
-
May 11th, 2001, 02:14 PM
#3
Re: Do you know if VB has a similiar "continue" statement like in C?
The only way that i know of is to set up a label, just before the end of the loop and when a certain condition is met, jump to that label:
for i = 1 to 20
if i mod 7 = 0 then
Goto NextOne
else
DoSomethingElse
end if
NextOne:
next i
something like that should work.
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
-
May 11th, 2001, 02:16 PM
#4
Re: Do you know if VB has a similiar "continue" statement like in C?
ooops sorry... that's what I get for reading too fast
-
May 14th, 2001, 08:27 AM
#5
Re: Do you know if VB has a similiar "continue" statement like in C?
...but you could do the contrary:
do something only if it matches your criteria,
else... do nothing and go on counting!
ie:
for i = 1 to 20
'if matched, do something
if i mod 7 <> 0 then
DoSomethingElse
end if
'if not matches, do nothing and just
'add 1 to i
next i
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
May 14th, 2001, 07:18 PM
#6
Re: Do you know if VB has a similiar "continue" statement like in C?
How about...
for i = 1 to 20
'Check for skip condition
If i = 4 then
i = i + 1
else 'Do work
Tmp = Tmp + i
End If
next i
The loop will add i to Tmp until i = 4, this iteration is skipped, then the loop continues with 5 to add i to Tmp. Is this more what you meant?
Hope this helps.
Spectre
-
May 14th, 2001, 07:40 PM
#7
Re: Do you know if VB has a similiar "continue" statement like in C?
It is a bad practice to change the loop index inside a loop. It can lead to errors that are difficult to debug. You could do with a Do...Loop statement instead, if the index needs to be changed.
-
May 15th, 2001, 06:03 AM
#8
Re: Do you know if VB has a similiar "continue" statement like in C?
I've been using this technique for almost 10 years and have yet for it to cause a problem - let alone an error that is hard to find, however, if you are uncomfortable with it don't do it.
Hope this helps.
Spectre
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|