VB.Net 教程:Each…Next 循环

返回到: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 – 循环

作者:terry,如若转载,请注明出处:https://www.web176.com/vbnet_api/11448.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年3月1日 下午10:43
下一篇 2023年3月1日 下午10:46

相关推荐

发表回复

登录后才能评论