Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a VB equivalent to C#'s 'continue' and 'break' statements?

For sake of argument, how could I do this in VB?

foreach foo in bar
{
   if (foo == null)
       break;

   if (foo = "sample")
       continue;

   // More code
   //...
}
like image 830
Jude Allred Avatar asked Sep 10 '09 00:09

Jude Allred


People also ask

Is VB similar to C#?

Though C# and VB.NET are syntactically very different, that is where the differences mostly end. Microsoft developed both of these languages to be part of the same .NET Framework development platform. They are both developed, managed, and supported by the same language development team at Microsoft.

Is VB.NET C based?

It is pronounced as Visual Basic . NET, which is an updated feature and version of Classic Visual Basic 6.0. It is pronounced as "C SHARP" language, that belongs to the C family.

Is VB.NET similar to C++?

The main difference between Visual Basic and Visual C++ is that Visual Basic is an Object Oriented Programming Language while Visual C++ is an Integrated Development Environment (IDE). Visual Basic is a user-friendly programming language developed by Microsoft.

Is VB faster than C#?

It is that VB computes the loop bound once while C# computes the loop condition on each iteration. It is just a fundamental difference in the way the languages were intended to be used. ...is slightly faster than the equivalent in VB.


2 Answers

-- Edit:

You've changed your question since I've answered, but I'll leave my answer here; I suspect a VB.NET programmer will show you how to implement such a loop. I don't want to hurt my poor C# compilers feelings by trying...

-- Old response:

I believe there is

Continue While
Continue For

and

Exit While
Exit For
like image 65
Noon Silk Avatar answered Sep 28 '22 06:09

Noon Silk


I thought a VB.NET example may help in the future:

Sub breakTest()
    For i = 0 To 10
        If (i = 5) Then
            Exit For
        End If
        Console.WriteLine(i)
    Next
    For i = 0 To 10
        If (i = 5) Then
            Continue For
        End If
        Console.WriteLine(i)
    Next
End Sub

The output for break:

0
1
2
3
4

And for continue:

0
1
2
3
4
6
7
8
9
10
like image 22
sansknwoledge Avatar answered Sep 28 '22 05:09

sansknwoledge