PowerShell - If 語句



一個 if 語句由一個布林表示式後跟一個或多個語句組成。

語法

以下是一個 if 語句的語法:-

if(Boolean_expression) {
   // Statements will execute if the Boolean expression is true
}

如果布林表示式求值為 true,則 if 語句中的程式碼塊將被執行。如果不是,則在 if 語句結束後的第一組程式碼(在閉合大括號後)將被執行。

流程圖

If Statement

示例

$x = 10

if($x -le 20){
   write-host("This is if statement")
}

這將生成以下結果:-

輸出

This is if statement.
powershell_conditions.htm
廣告