S_pot
C#_break키워드 본문
// 짝수를 입력하면 종료, 홀수를 입력하면 반복
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 키워드");
}
'C#' 카테고리의 다른 글
C#_enum (0) | 2021.06.02 |
---|---|
C#_continue키워드 (0) | 2021.06.01 |
C#_foreach반복문 (0) | 2021.06.01 |
C#_역 for 반복문 (0) | 2021.05.31 |
C#_for 반복문 (0) | 2021.05.31 |