Powershell-nested-if-statements-in-powershell

提供:Dev Guides
移動先:案内検索

Powershell-ネストされたIf Elseステートメント

if-elseステートメントをネストすることは常に有効です。つまり、ifまたはelseifステートメントを別のifまたはelseifステートメント内で使用できます。

構文

ネストされたif …​ elseの構文は次のとおりです-

if(Boolean_expression 1) {
  //Executes when the Boolean expression 1 is true
   if(Boolean_expression 2) {
     //Executes when the Boolean expression 2 is true
   }
}

_if_ステートメントをネストしたのと同様の方法で elseif …​ else をネストできます。

$x = 30
$y = 10

if($x -eq 30){
   if($y -eq 10) {
      write-host("X = 30 and Y = 10")
   }
}

これは、次の結果を生成します-

出力

X = 30 and Y = 10