Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Is there a special VB statement to let you jump to the next iteration in a loop?

Jump to next iteration in a loop

Say you got a loop like the one below.  How do I accomplish the same task without the goto statement?

  For Each MyControl In ControlCollection
    If TypeOf MyControl Is Whatever Then Goto SkipThisOne
    ' Provide code here to work with valid MyControl
SkipThisOne:
  Next MyControl

And, NO - I do NOT mean do as follows...

For Each MyControl In ControlCollection
        If not TypeOf MyControl Is Whatever Then
        ' Provide code here to work with valid MyControl
       end if
       Next MyControl

tia

avi

 
 
0
progtw
Asked:
progtw
  • 2
  • 2
2 Solutions
 
drydenhoggCommented:
In terms of a built in collection type used in a for..each loop basically no. You have the choices of using program flow logic or goto statements, the latter of which I would say never use.


0
 
doobdaveCommented:
Hi,
What's wrong with using the second method:
For Each MyControl In ControlCollection
        If not TypeOf MyControl Is Whatever Then
        ' Provide code here to work with valid MyControl
       end if
       Next MyControl
?

It looks like a much better solution than using thhe goto statement.

Best Regards,

David
0
 
progtwAuthor Commented:
to doobdave:

>> What's wrong with using the second method:

But there isn't a special VB statement  to let you jump to the next iteration in a loop?

avi
0
 
drydenhoggCommented:
There is no special statement that allows you to skip to next, no.
0
 
progtwAuthor Commented:
foooo-ey!

avi
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now