1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visual C# 2013 パーフェクトマスター 5章 制御構造

Posted at

Amazon.co.jp: VisualC#2013パーフェクトマスター (Perfect Master SERIES): 金城 俊哉: 本

自分の不明点をとりまとめ。理解できているところは割愛。

選択ステートメント

if文

            if(x == 1)
            {
                Console.WriteLine("true");
            
            }
            else
            {
                Console.WriteLine("else");
            }

{}を省略することもできる

            if(x == 1)Console.WriteLine("true");
            else Console.WriteLine("else");

switchステートメント

            switch (x)
            {
                case 1:
                    Console.WriteLine("1");
                    break;
                case 2:
                    Console.WriteLine("2");
                    break;
                default:
                    Console.WriteLine("default");
                    break;
            }

繰り返しステートメント

同じ処理を繰り返す「while」

            int i = 1;
            while(i<=5)
            {
                Console.WriteLine(i);
                i++;
            }

繰り返し処理を最低1回は行う「do while」

            int i = 1;
            do
            {
                Console.WriteLine(i);
                i++;
            }
            while (i <= 5);

繰り返しとカウンター定義を一度に行う「for」

            for (int i = 1; i <= 5; i++)
            {
                Console.WriteLine(i);
            }

コレクション内すべてのオブジェクト「foreach」

            var arry = new[] {1,2,3,4,5};
            foreach(var item in arry)
            {
                Console.WriteLine(item);
            }
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?