Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

For next loops - question

For next loops - question

For next loops - question

Some of you familiar with C may know the "continue" command, for example:

for (i=0; i<5; i++) // equivalent to For i = 0 To 5 in VB
    if (some condition)

    some statement;
} // In VB this would say Next i

In this case, if "some condition" is satisfied, then instead of execting "some statement", the program moves on immediately to the next "go-round" in the loop.

I have been looking for a similar function on VB on the internet, but without success. Could anybody confirm whether this functionality is available in VB or not?

Many thanks.

RE: For next loops - question

I think it's very poor programming style to exit a loop prematurely.  If you're not going to iterate the number of times specifed by the 'for' statement, then don't use a for loop; use a while loop.

That being said, 'Exit For' is the VB command that you're looking for.

Good Luck
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: For next loops - question

I think Grafton is looking for a line that checks some condition, if the condition is true then skip down to the "NEXT" statement and continue in the loop.  If the condition is flse, then execute the statements inside the loop and then hit the "NEXT" line.  If I am correct, then the syntax would be:

For i = 1 to 5
 IF condition = true then goto SkipToNext


For i = 1 to 5
 IF condition = false then

RE: For next loops - question

Yes, I did misread the question.

Perhaps the simplest answer would be

For i = 1 to 10
   If (Not (SomeCondition)) Then
      <execute body of loop>
   End If
Next i

Good Luck
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close