While...Wend
 
控制流程语句进行循环

语法

While [condition ]
[statement block ]
Wend

说明

While语句将导致statement block 中的以下一组语句重复执行,而表达式condition 的计算结果为true。

如果condition 首次执行While语句时condition 计算结果为false,则跳过statement block ,并在封闭的Wend语句之后立即执行恢复。

如果在statement block 内遇到Exit While语句,则循环将被终止,并在封闭的Wend语句之后立即恢复执行。如果遇到Continue While语句,则跳过statement block 的其余部分,并在While语句中执行恢复。

像所有控制流语句一样,While语句可以嵌套,也就是说,它可以在另一个While语句的语句块中使用。

note: the While 关键字 is also used in the Do...Loop statement to indicate the type of comparison. Used in this way, the Do statement becomes functionally equivalent to the While statement, so do not confuse their enclosing keywords Loop and Wend, respectively.

例子

在本示例中,循环用于通过向后循环来反转字符串。如果index小于0 (0 being the first index in the string) ,则循环停止。
Dim As String sentence                          ''字符串反向
sentence = "敏捷的棕色狐狸跳过了懒狗。"

Dim As String ecnetnes
Dim As Integer index
index = Len( sentence ) - 1                     ''指向最后一个字符
While( index >= 0 )                             ''第一个字符后停止
  ecnetnes += Chr( sentence[index] )           ''将字符附加到新字符串
  index -= 1
Wend

Print "原版的: ””" ; sentence ; """"
Print "反转:“”" ; ecnetnes ; """"

End 0


方言差异

与QB差别

  • 没有

参考