- 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 中的 Do..Until 循环
当我们希望在条件为假时重复一组语句时,将使用Do..Until循环。条件可以在循环开始时或结束时检查。
语法
VBScript 中Do..Until循环的语法为 −
Do Until condition [statement 1] [statement 2] ... [statement n] [Exit Do] [statement 1] [statement 2] ... [statement n] Loop
流程图
示例
下面的示例使用Do..Until循环在循环开始时检查条件。仅当条件为假时才会执行循环内的语句。当条件变为真时,它退出循环。
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
i = 10
Do Until i>15 'Condition is False.Hence loop will be executed
i = i + 1
Document.write("The value of i is : " & i)
Document.write("<br></br>")
Loop
</script>
</body>
</html>
执行上述代码后,它会在控制台中打印以下输出。
The value of i is : 11 The value of i is : 12 The value of i is : 13 The value of i is : 14 The value of i is : 15 The value of i is : 16
备用语法
还有一个备用Do..Until循环语法,可以在循环结束时检查条件。下面通过示例解释这两个语法的重大区别。
Do [statement 1] [statement 2] ... [statement n] [Exit Do] [statement 1] [statement 2] ... [statement n] Loop Until condition
流程图
示例
下面的示例使用Do..Until循环在循环结束时检查条件。即使条件为真,循环内的语句也会执行一次。
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
i = 10
Do
i = i + 1
Document.write("The value of i is : " & i)
Document.write("<br></br>")
Loop Until i<15 'Condition is True.Hence loop is executed once.
</script>
</body>
</html>
执行上述代码后,它会在控制台中打印以下输出。
The value of i is : 11
vbscript_loops.htm
广告