continue

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Anyone else wish Vb.Net had a continue keyword such as
that in C based languages? It would be nice to send
execution to the begining of the loop without having
to 'GoTo'.
 
Dave said:
Anyone else wish Vb.Net had a continue keyword such as
that in C based languages? It would be nice to send
execution to the begining of the loop without having
to 'GoTo'.

What exactly are you trying to do? Loops in VB don't need a GoTo:

For Each obj in AnyCollection
....
Next

For i = 0 to 10
....
Next

Do While i < 10
....
Loop

While i<10
....
End While

--


Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
 
Hi Mike,

Here's just one format.

For Each Foo in LotsOfFoos
Select Foo.Number
Case 1:
DoSomethingAmazing
Continue
Case 2:
DoSomethingSpecial
Continue
Case 3:
DoSomethingDaft
Case 4:
DoSomethingFunny
End Select
DoSomethingSerious '3 and 4
Next

The use of Continue saves needing an If after the Select in order to
ensure that only 3 and 4 get serious.

It also makes it perfectly clear that 1 and 2 have just a single role
within the For loop.

Regards,
Fergus
 
In a weblog I read that they will introduce it in Whidbey. Maybe it's
rumor, I don't know.

At the longhorn SDK site:

http://longhorn.msdn.microsoft.com/

They have the VB.Net specs but I think they have not been updated with the
new features, because there is no mention of generics or partial types on
that spec, even though the corresponding C# spec does list those things.
 
In a weblog I read that they will introduce it in Whidbey. Maybe it's
rumor, I don't know.

;-)

At this location is information on the new version of Visual Basic:

http://msdn.microsoft.com/vbasic/whidbey/

It includes Generics, Operator Overloading, Unsigned Types, Using Block,
and the Continue Statement. It gives exmples of the Continue statement
like this:

Public Sub PeterPiper()
Dim s As Char() = "peter piper picked pickled peppers"
Dim i As Integer

For i = 0 To (s.Length() - 1)
'interested only in p's
If Not (s(i).Equals("p"c)) Then Continue For
s(i) = "P"c
Next
Console.WriteLine(s)
End Sub


And the Using Block:

Imports System.Drawing

Sub Main()
'Create a new font object using expensive system
'resources.
Using theFont As New Font("Arial", 10.0F)
txtFontA.Font = theFont
txtFontA.Text = "Hello Bebbe Cow!"
End Using
'The Dispose method has been called on our Font
'releasing the system resources.

'Repeat the process reading text from a file.
'Note that the filename is invalid in this case.
Dim sFilename As String = "C:\Invalid*Test*File"
Using theFont As New Font("Arial", 10.0F)
txtFontA.Font = theFont
'This will throw an exception because the filename is invalid
txtFontA.Text=My.Computer.FileSystem.ReadAllText(sFilename)
End Using
'The dispose method has been called even though
¡the code threw an exception.
End Sub


Very interesting and exciting changes for VB ahead!
 
Back
Top