do ~ while()

2016. 12. 12. 12:31C# 콘솔( Console )/반복문

1. MSDN

do( C# 참조 )


2. while(조건식)

while()



            do 
            { 
                실행문
            } 
            while (조건);

 


   -> while()문과는 다르게 do ~ while()문은 실행문을 한 번 실행한 후 조건문을 확인합니다.
즉, 최소 1번은 실행된다고 보시면 됩니다.
   -> while()문 괄호 뒤에 세미콜론(;)로 마침표를 찍어주지 않으면 에러가 발생합니다


ex1)


        static void Main(string[] args) 
        { 
            int cnt = 0; 

            do 
            { 
                Console.WriteLine("cnt = " + cnt); 
                cnt++; 
            } 
            while (cnt < 10); 
        }

 



ex2) while()문에 ;(세미콜론)을 찍지 않은 경우


 

        static void Main(string[] args) 
        { 
            int cnt = 0; 

            do 
            { 
                Console.WriteLine("cnt = " + cnt); 
                cnt++; 
            } 
            while (cnt < 10)
        }










'C# 콘솔( Console ) > 반복문' 카테고리의 다른 글

중첩 while()문을 이용한 구구단  (0) 2016.12.12
while()문을 이용한 구구단  (0) 2016.12.12
중첩 반복문( for()문 )을 이용한 구구단  (0) 2016.12.12
while()  (0) 2016.12.12
for()문  (0) 2016.12.12