본문 바로가기
Study/C#

[C#][Study][기초다지기] do-while 문

by 스테디코디스트 2023. 9. 23.
반응형

do-while 문

-  while문이 적어도 한 번은 실행되는 것이 보장됨

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace do_while
{
    class Program
    {
        static void Main(string[] args)
        {
            int table, i, res;
            table = 12;
            i = 1;
            do
            {
                res = table * i;
                Console.WriteLine("{0} x {1} = {2}", table, i, res);
                i++;
            }            
            while (i == 10); // 세미콜론 써야함에 유의!
            // i는 10이 아니지만 문장을 먼저 실행하고 조건을 체크하기 때문에 한번은 출력을 하게된다.            
 
            Console.ReadLine();
        }
    }
}