VBScript If..ElseIf..Else 语句



一个 If 语句后跟一个或多个 ElseIf 语句,其中包含布尔表达式,然后后跟一个默认 else 语句,当所有条件变为 false 时执行此语句。

语法

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

流程图

VBScript If..Elseif..Else statement

示例

<!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.htm
广告
© . All rights reserved.