当前位置: 首页 > 文档资料 > VB.Net 中文教程 >

嵌套的 Select Case 语句(nested Select Case statements)

优质
小牛编辑
116浏览
2023-12-01

它为集合中的每个元素重复一组语句。 此循环用于访问和操作数组或VB.Net集合中的所有元素。

此循环结构的语法是 -

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

例子 (Example)

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