VB.Net 教程:While… End While 循环

返回到:VB.Net – 循环

只要给定条件为True,While… End While就执行一系列语句。

这个循环结构的语法是:

While condition
    [ statements ]
    [ Continue While ]
    [ statements ]
    [ Exit While ]
    [ statements ]
End While

这里,语句可以是单个语句或语句块。 条件可以是任何表达式,true是逻辑true。 当条件为真时,循环迭代。
当条件变为假时,程序控制传递到紧随循环之后的行。

流程图:

VB.Net 教程:While... End While 循环

这里,While循环的关键点是循环可能永远不会运行。 当条件被测试并且结果为false时,循环体将被跳过,while循环之后的第一条语句将被执行。

示例:

Module loops
   Sub Main()
      Dim a As Integer = 10
      ' while loop execution '
      While a < 20
          Console.WriteLine("value of a: {0}", a)
          a = a + 1
      End While
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

返回到:VB.Net – 循环

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

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

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注