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

流程图

VBScript:For循环

这是For循环中的控制流程:

  • 对于步骤首先被执行。该步骤允许您初始化任何循环控制变量并增加步数计数器变量。
  • 其次,评估条件。如果为true,则执行循环主体。如果为false,则循环主体不执行,并且控制流仅在For循环之后跳转到下一条语句。
  • 在for循环的主体执行之后,控制流跳至Next语句。该语句允许您更新任何循环控制变量。根据步数计数器值进行更新。
  • 现在将再次评估条件。如果为true,则循环执行并重复执行过程(循环主体,然后是递增步,然后再次是条件)。条件变为false之后,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

作者:terry,如若转载,请注明出处:https://www.web176.com/vbscript/1255.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2020年12月9日 下午5:25
下一篇 2020年12月9日 下午5:34

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注