今回はfor文について説明したいと思います。
PowerShellにおけるforループの構文は次の通りです。
for ( 初期化; 評価式; インクリメント ){ 評価式がTrueの場合に実行するスクリプト}
ただし、PowerShellでは比較演算子の表し方が独特であるため、慣れるまでは少し違和感があります。
比較演算子は比較演算子(PowerShell 入門) を参照ください。
c言語やC#では
for ( i = 0; i < 5; i++ ) { }
と書くところを、PowerShellでは
for ( $i = 0; $i -lt 5; $i++ ) { }
と記述します。
実際の使用例は下記の通りです。(for文を使用してカウントを表示する例です)
PS > for ( $i = 0; $i -lt 5; $i++ ) >> { >> Write-Host ("カウント" + $i) >> } >> カウント0 カウント1 カウント2 カウント3 カウント4
Theme design by Jelle Druyts
Pick a theme: BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2 BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, HIRO
E-mail