2
2

More than 5 years have passed since last update.

Powershell > for文と変数のカウントアップ

Last updated at Posted at 2016-01-23
動作環境
Windows 8.1 pro (64bit)

Powershellでfor文の書き方と変数のカウントアップの練習

参考 http://www.atmarkit.co.jp/ait/articles/0709/20/news125_3.html

function Test_counter()
{
    echo "test counter"
    $cnt = 1
    for($idx=0; $idx -lt 5; $idx++) {
        echo $cnt
        $cnt++;
        if ($cnt -ge 3) {
            echo "large than 3"
        }
    }
}

function main() 
{
    Test_counter
    exit
}
結果
test counter
1
2
larger than 3
3
larger than 3
4
larger than 3
5
larger than 3

$cnt++する位置はif文の後のほうにすべきだった。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2