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

这个循环结构的语法是:
While condition[ statements ][ Continue While ][ statements ][ Exit While ][ statements ]End While
这里,语句可以是单个语句或语句块。 条件可以是任何表达式,true是逻辑true。 当条件为真时,循环迭代。
当条件变为假时,程序控制传递到紧随循环之后的行。
流程图:

这里,While循环的关键点是循环可能永远不会运行。 当条件被测试并且结果为false时,循环体将被跳过,while循环之后的第一条语句将被执行。
示例:
Module loopsSub Main()Dim a As Integer = 10' while loop execution 'While a < 20Console.WriteLine("value of a: {0}", a)a = a + 1End WhileConsole.ReadLine()End SubEnd Module
当上述代码被编译和执行时,它产生以下结果:
value of a: 10value of a: 11value of a: 12value of a: 13value of a: 14value of a: 15value of a: 16value of a: 17value of a: 18value of a: 19
转载本站内容时,请务必注明来自W3xue,违者必究。


优化或报错有奖
皖公网安备34020702000426号