在VB。NET里怎么实现类似C#中continue的功能

类别:.NET开发 点击:0 评论:0 推荐:

如下C#代码:
int sum=0;
for(int i=1;i<101;i++)
{
 if(i%2!=0)
 {
  continue;
 }
 sum+=i;
}

可以考虑用以下VB.NET代码实现:
Dim sum As Integer, i As Integer
For i = 1 To 100
   If (i Mod 2 = 0) Then
     sum = sum + i
   End If
Next


Dim sum As Integer, i As Integer
For i = 1 To 100
  If (i Mod 2 <> 0) Then
     GoTo continue
  End If
  sum = sum + i
continue:
Next


另外在VB.NET 2005,已经实现了continue语法
For i As Integer = 0 To 100

     ' If i = 50 skip Console.Writeline statement

     If i = 50 Then Continue For

     Console.WriteLine(i.ToString)

Next

 

' Do While using Continue statement.

Dim ii As Integer = 1

Do While ii < 100

     ii += 1

     ' If i = 50 skip Console.Writeline statement

     If ii = 50 Then Continue Do

     Console.WriteLine(ii.ToString)

Loop

 

' While using Continue statement.

Dim iii As Integer = 1

While iii < 100

     iii += 1

     ' If i = 50 skip Console.Writeline statement

     If iii = 50 Then Continue While

     Console.WriteLine(iii.ToString)

End While

具体介绍查看:
http://msmvps.com/mcintyre/archive/2004/06/18/8449.aspx

本文地址:http://com.8s8s.com/it/it41232.htm