VBScript If..ElseIf..Else 语句
一条 If 语句,后跟一个或多个由布尔表达式组成的 ElseIf 语句,然后跟一个默认的 else 语句,该语句执行 当所有条件都变为假时。
语法
VBScript 中 If-ElseIf-Else 语句的语法为 −
If(boolean_expression) Then Statement 1 ..... ..... Statement n ElseIf (boolean_expression) Then Statement 1 ..... .... Statement n ElseIf (boolean_expression) Then Statement 1 ..... .... Statement n Else Statement 1 ..... .... Statement n End If
流程图
示例
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim a
a = -5
If a > 0 Then
Document.write "a is a POSITIVE Number"
ElseIf a < 0 Then
Document.write "a is a NEGATIVE Number"
Else
Document.write "a is EQUAL than ZERO"
End If
</script>
</body>
</html>
执行上述代码时,会产生以下结果 −
a is a NEGATIVE Number

vbscript_decisions.html