
- VBScript 教程
- VBScript - 主頁
- VBScript - 概覽
- VBScript - 語法
- VBScript - 啟用
- VBScript - 放置
- VBScript - 變數
- VBScript - 常量
- VBScript - 運算子
- VBScript - 決策
- VBScript - 迴圈
- VBScript - 事件
- VBScript - Cookie
- VBScript - 數字
- VBScript - 字串
- VBScript - 陣列
- VBScript - 日期
- 高階 VBScript
- VBScript - 過程
- VBScript - 對話方塊
- 面向物件的 VBScript
- VBScript - 正則表示式
- VBScript - 錯誤處理
- VBScript - 其他語句
- 有用的 VBScript 資源
- VBScript - 問題與解答
- 便捷指南 - VBScript
- 有用的 VBScript 資源
- 討論 - VBScript
VBScript For 迴圈
for 迴圈是一種重複控制結構,可以讓開發者高效地編寫迴圈,從而能執行特定次數的迴圈。
語法
VBScript 中 for 迴圈的語法如下 −
For counter = start To end [Step stepcount] [statement 1] [statement 2] .... [statement n] [Exit For] [statement 11] [statement 22] .... [statement n] Next
流程圖

以下是 For 迴圈的控制流 −
首先執行 For 步驟。此步驟允許多個開發者初始化迴圈控制變數並增加步長計數器變數。
其次,對 條件 進行求值。如果結果為真,則執行迴圈主體。如果結果為假,則迴圈主體不會執行,並且控制流會跳轉到 For 迴圈之後的下一條語句。
執行 for 迴圈主體後,控制流會跳轉到 Next 語句。此語句允許多個開發者更新迴圈控制變數。其更新基於步長計數器值。
現在重新對條件進行求值。如果結果為真,則執行迴圈,並且此過程會不斷重複(迴圈主體,然後增加步長,最後再判斷條件)。在條件變為假後,For 迴圈會終止。
示例
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim a : a = 10 For i = 0 to a Step 2 'i is the counter variable and it is incremented by 2 document.write("The value is i is : " & i) document.write("<br></br>") Next </script> </body> </html>
編譯並執行以上程式碼後,它會產生以下結果 −
The value is i is : 0 The value is i is : 2 The value is i is : 4 The value is i is : 6 The value is i is : 8 The value is i is : 10
vbscript_loops.htm
廣告