class Program
{
static void Main(string[] args)
{
string choice = string.Empty;
do
{
start:
int output = 0;
int number = 0;
Console.WriteLine("Please input a number for it to be counted!");
bool conversion = int.TryParse(Console.ReadLine(), out output);
if (number < 1000)
{
switch (conversion)
{
case true:
while (number <= output)
{
Console.Write(number + " ");
number += 2;
}
break;
case false:
Console.WriteLine("ERROR: INVALID INPUT!");
goto start;
}
}
else
{
Console.WriteLine("APPLICATION ERROR: NUMBER MUST BE BELOW OR AT 1000 TO PREVENT OVERFLOW!");
return;
}
do // Here is the beginning of the do code
{
Console.WriteLine("\n Do you want to continue - Yes or No");
choice = Console.ReadLine();
if (choice.ToUpper() != "YES" && choice.ToUpper() != "NO")
{
Console.WriteLine("ERROR INVALID INPUT: Only input Yes or No!");
}
} while (choice.ToUpper() != "YES" && choice.ToUpper() != "NO");
} while (choice.ToUpper() == "YES");
}
}
나는이 문에서 do while 루프를 몇 개 사용하고 있지만 사용자가 할당 된 정수 이외의 값을 넣을 때 "ERROR INVALID INPUT :"결과를 루프에 넣는 방법이 트롭다. (즉, 십진수 또는 분수를 넣는 것) 또는 문자열을 넣는 경우. 나는 do while 문을 어디에 두어야 하는지를 알아 내는데 어려움을 겪고 있기 때문에 단순히 goto를 사용했다. 만약 누군가가 어떻게 그 하나의 고토를 do while 루프로 대체 할 수 있었는지 나에게 보여줄 수 있다면, 나는 매우 위대 할 것이다. (당신은 나에게 내가 아직도 내가 아마 이해하지 못할 새로 온 사람 때문에 내 코드를 더 최적화 할 수있는 방법을 보여 주면 참고하지만, 환영은 당신의 최고의 기회를 제공하기 위해!)어떻게이 goto를 do while 루프로 변환 할 수 있습니까?
마찬가지로 '계속; – SimpleVar