VBScript If 語句



If 語句由一個布林表示式後跟一條或多條語句組成。如果條件為真,則執行If 條件下方的語句。如果條件為假,則執行If 迴圈後的語句。

語法

VBScript 中If 語句的語法如下 −

If(boolean_expression) Then
   Statement 1
	.....
	.....
   Statement n
End If

流程圖

VBScript if statement

示例

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim a : a = 20
         Dim b : b = 10

         If a > b Then
            Document.write "a is Greater than b"
         End If

      </script>
   </body>
</html>

執行上述程式碼後,將生成以下結果 −

a is Greater than b
vbscript_decisions.htm
廣告