Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In a do loop how do I skip to the next iteration?

 

In java, there's the 'continue' keyword...

 

If there's no 'continue' for a do loop what about while loops or for loops?

 

My book really doesn't tell me anything related to this...

 

Thanks.

  • *Experts*
Posted

I suppose the best way would be to use a Boolean.

 

Do While MyCondition = True
 Dim continue As Boolean

 'In C#, this would look like [b]if (This == "That") continue;[/b]
 If This = "That" Then continue = True

 'This part skips all the code after the continue line, if necessary
 If Not continue Then 'You did not choose to go to the next iteration
   'Nested continues should work as well.
   'C#: if (Equation = (4+3/5)^4) continue;
   If Equation = (4+3/5)^4 Then continue = True
   If Not continue Then
     'Once again, you didn't choose to go to the next iteration
   End If
 End If
Loop

I don't know if this is a total reproduction of the behaviour of

continue, nor have I tested it, but it should work. :-\ Best you can

do is give it a shot.

Posted
fact is, guys, that vb .NET _lacks_ a continue statement. That's a shame ,though, because it vb.net is a great language overall. Some may say nothing is perfect...
  • *Experts*
Posted

They are useful in some situations, but I haven't had the need for one in years. When I did (in VB6), I used an "If...Then" as VolteFace showed in his first example.

 

You're right, it's a shame they didn't include something seemingly so simple in VB.NET. But then, C# and VB.NET are different languages...

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...