目录

虽然......结束了(While... End While)

只要给定条件为True,它就会执行一系列语句。

此循环结构的语法是 -

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

这里,语句可以是单个语句或语句块。 条件可以是任何表达式,而true是逻辑真的。 当条件为真时,循环迭代。

当条件变为假时,程序控制将立即传递到循环之后的行。

流程图 (Flow Diagram)

在VB.Net中循环

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

例子 (Example)

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
↑回到顶部↑
WIKI教程 @2018