- 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 嵌套 If 语句
在另一个 If 或 ElseIf 语句内部的 If 或 ElseIf 语句。内部 If 语句根据最外部 If 语句执行。这使得 VBScript 能够轻松处理复杂的条件。
语法
VBScript 中嵌套 if 语句的语法为 −
If(boolean_expression) Then
Statement 1
.....
.....
Statement n
If(boolean_expression) Then
Statement 1
.....
.....
Statement n
ElseIf (boolean_expression) Then
Statement 1
.....
....
Statement n
Else
Statement 1
.....
....
Statement n
End If
Else
Statement 1
.....
....
Statement n
End If
示例
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim a
a = 23
If a > 0 Then
Document.write "The Number is a POSITIVE Number"
If a = 1 Then
Document.write "The Number is Neither Prime NOR Composite"
Elseif a = 2 Then
Document.write "The Number is the Only Even Prime Number"
Elseif a = 3 Then
Document.write "The Number is the Least Odd Prime Number"
Else
Document.write "The Number is NOT 0,1,2 or 3"
End If
ElseIf a < 0 Then
Document.write "The Number is a NEGATIVE Number"
Else
Document.write "The Number is ZERO"
End If
</script>
</body>
</html>
执行以上代码后,产生以下结果 −
The Number is a POSITIVE Number The Number is NOT 0,1,2 or 3
vbscript_decisions.htm
广告