- 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 Exit For 语句
当我们想要根据某些条件退出 For 循环时,会使用 Exit For 语句。当执行 Exit For 时,控制权会立即跳至 For 循环之后的下一条语句。
语法
VBScript 中 Exit For 语句的语法为:-
Exit For
流程图
示例
以下示例使用了 Exit For。如果计数器值达到 4,则退出 For 循环,控制权会立即跳至 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>")
If i = 4 Then
i = i*10 'This is executed only if i = 4
document.write("The value is i is : " & i)
Exit For 'Exited when i = 4
End If
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 : 40
vbscript_loops.htm
广告