如下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