Solved

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

Posted on 2006-11-21
5
186 Views
Last Modified: 2010-04-30
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
Comment
Question by:progtw
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:drydenhogg
Comment Utility
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
 
LVL 8

Assisted Solution

by:doobdave
doobdave earned 40 total points
Comment Utility
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
 

Author Comment

by:progtw
Comment Utility
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
 
LVL 8

Accepted Solution

by:
drydenhogg earned 85 total points
Comment Utility
There is no special statement that allows you to skip to next, no.
0
 

Author Comment

by:progtw
Comment Utility
foooo-ey!

avi
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now