PowerShell 带有中断的简单开关

示例

该break关键字可以在switch语句中使用评估所有条件之前退出的声明。

例:

switch('Condition')
{
  'Condition'
  {
    'First Action'
  }
  'Condition'
  {
    'Second Action'
    break
  }
  'Condition'
  {
    'Third Action'
  }
}

输出:

First Action
Second Action

由于break第二个操作中的关键字,因此不评估第三个条件。