「PowerShell」while文を使うサンプル

書式
while (条件式)
{
処理コード
}
条件がtrueの間、処理を繰り返します。
条件式がfalseの場合、処理を終了します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$i = 10
while ($i -lt 15) {
Write-Host($i)
$i = $i + 1
}
$i = 10 while ($i -lt 15) { Write-Host($i) $i = $i + 1 }
$i = 10

while ($i -lt 15) {
    Write-Host($i) 
    $i = $i + 1
}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
PS C:\study\powershell> ./test.ps1
10
11
12
13
14
PS C:\study\powershell> ./test.ps1 10 11 12 13 14
PS C:\study\powershell> ./test.ps1
10
11
12
13
14

 

PowerShell

Posted by arkgame