본문 바로가기
Study/C#

[C#][Study][기초다지기] goto 문

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

goto 문

- label을 선언한 곳으로 돌아감

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace goto_statements
{
    class Program
    {
        static void Main(string[] args)
        {
            string name;
 
        label: // 레이블 생성 -> 콜론 주의!
 
            Console.WriteLine("Enter your name: ");
            name = Console.ReadLine();
 
            Console.WriteLine("Welcome {0}", name);
            Console.WriteLine("Press Ctrl + C for Exit\n");
 
            goto label; // 레이블로 돌아감(반복)     
        }
    }
}