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
广告