포스트

(C#) 7. 코드의 흐름 제어 (while)

while

while

  • 최초 작성일: 2021년 3월 21일(월)

##

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;

namespace WhileEX
{
    class Program
    {
        static void Main(string[] args)
        {
            // while 반복문
            int count = 5;
            string answer;

            while (count > 0)
            {
                Console.WriteLine("Hello World!");
                count--;
            }

            do
            {
                Console.WriteLine("(y/n) : ");
                answer = Console.ReadLine();
            } while (answer != "y");

            Console.WriteLine("end");
        }
    }
}

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.