
- PowerShell 教程
- PowerShell - 主頁
- PowerShell - 概述
- PowerShell - 環境設定
- PowerShell - Cmdlet
- PowerShell - 檔案和資料夾
- PowerShell - 日期和時間
- PowerShell - 檔案輸入/輸出
- PowerShell - 高階 Cmdlet
- PowerShell - 指令碼編寫
- PowerShell - 特殊變數
- PowerShell - 運算子
- PowerShell - 迴圈
- PowerShell - 條件
- PowerShell - 陣列
- PowerShell - 雜湊表
- PowerShell - 正則表示式
- PowerShell - 反引號
- PowerShell - 括號
- PowerShell - 別名
- 有用的 PowerShell 資源
- PowerShell - 快速指南
- 有用的 PowerShell 資源
- PowerShell - 討論
PowerShell - If 語句
一個 if 語句由一個布林表示式後跟一個或多個語句組成。
語法
以下是一個 if 語句的語法:-
if(Boolean_expression) { // Statements will execute if the Boolean expression is true }
如果布林表示式求值為 true,則 if 語句中的程式碼塊將被執行。如果不是,則在 if 語句結束後的第一組程式碼(在閉合大括號後)將被執行。
流程圖

示例
$x = 10 if($x -le 20){ write-host("This is if statement") }
這將生成以下結果:-
輸出
This is if statement.
powershell_conditions.htm
廣告