TOP >
lesson4
Lesson 4-5(switch)
Switch
条件分岐は以下
switch($x){
1 {Write-Output '変数$xは1です。'}
2 {Write-Output '変数$xは2です。'}
3 {Write-Output '変数$xは3です。'}
default {Write-Output '変数$xは1、2、3ではありません。'}
}
結構見たまま。
switchを抜けるには、breakを使用する。
1 {
Write-Output '変数$xは1です。'
break
}
また、ワイルドカードの使用も可能。
switch -wildcard ($x){
"a*" {Write-Output 'aで始まる'}
"a?" {Write-Output 'aと一文字'}
"???" {Write-Output '三文字'}
}