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循环中的控制流程:
<!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