VBScript While…Wend 循环



While..Wend 循环中,如果条件为真,则执行所有语句,直到遇到Wend 关键字。

如果条件为假,则退出循环,并且控制跳转到Wend 关键字之后的下一条语句。

语法

VBScript 中While..Wend 循环的语法为 -

While condition(s)
   [statements 1]
   [statements 2]
   ...
   [statements n]
Wend

流程图

While Loop Architecture

示例

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim Counter :  Counter = 10   
         While Counter < 15    ' Test value of Counter.
            Counter = Counter + 1   ' Increment Counter.
            document.write("The Current Value of the Counter is : " & Counter)
            document.write("<br></br>")
         Wend ' While loop exits if Counter Value becomes 15.
         
      </script>
   </body>
</html>

执行以上代码时,将在控制台打印以下输出。

The Current Value of the Counter is : 11 

The Current Value of the Counter is : 12 

The Current Value of the Counter is : 13 

The Current Value of the Counter is : 14 

The Current Value of the Counter is : 15
vbscript_loops.htm
广告
© . All rights reserved.