C#
C#_break키워드
S_pot
2021. 6. 1. 10:36
// 짝수를 입력하면 종료, 홀수를 입력하면 반복
static void Main1(string[] args)
{
while (true)
{
Console.WriteLine("숫자를 입력해주세요(짝수를 입력하면 종료): ");
int input = int.Parse(Console.ReadLine());
if (input % 2 == 0)
{
break;
}
}
}
// goto 키워드
// 중첩반복문을 한번에 벗어나고 싶을 때 사용
static void Main1(string[] args)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("외부 반복문");
for(int j = 0; j < 10; j++)
{
Console.WriteLine("내부 반복문");
goto doNotUse;
}
}
doNotUse:
Console.WriteLine("goto 키워드");
}