Vb.net-foreachnext-loops

提供:Dev Guides
移動先:案内検索

VB.Net-各…​次のループ

コレクション内の各要素に対してステートメントのグループを繰り返します。 このループは、配列または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