VBScript Exit Do 语句



当我们希望基于某些条件退出 Do 循环时,将使用一个 Exit Do 语句。它可以在 Do..WhileDo..Until 循环中使用。

执行 Exit Do 时,控制将立即跳转到 Do 循环后面的下一句语句。

语法

VBScript 中 Exit Do 语句的语法为 -

 Exit Do

流程图

VBScript Exit Do statement

示例

以下示例使用了 Exit Do。如果计数器的值达到 10,则会退出 Do 循环,并且控制会立即跳转到 For 循环后面的下一句语句。

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         i = 0
         Do While i <= 100
            If i > 10 Then
               Exit Do   ' Loop Exits if i>10
            End If
            document.write("The Value of i is : " &i)
            document.write("<br></br>")
            i = i + 2
         Loop   
         
      </script>
   </body>
</html>

运行以上代码时,将在控制台中输出以下内容。

The Value of i is : 0

The Value of i is : 2

The Value of i is : 4

The Value of i is : 6

The Value of i is : 8

The Value of i is : 10
vbscript_loops.htm
广告
© . All rights reserved.