VB.Net - Each...Next 迴圈



它對集合中每個元素重複一群語句。該迴圈用於訪問和運算元組或 VB.Net 集合中的全部元素。

此迴圈結構的語法是 -

For Each element [ As datatype ] In group
   [ statements ]
   [ Continue For ]
   [ statements ]
   [ Exit For ]
   [ statements ]
Next [ element ]

示例

Module loops
   Sub Main()
      Dim anArray() As Integer = {1, 3, 5, 7, 9}
      Dim arrayItem As Integer
     'displaying the values
      
      For Each arrayItem In anArray
         Console.WriteLine(arrayItem)
      Next
      Console.ReadLine()
   End Sub
End Module

當編譯和執行上述程式碼時,會產生以下結果 -

1
3
5
7
9
vb.net_loops.htm
廣告
© . All rights reserved.