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
廣告