문제

간단한 프로젝트를 개발하고 있지만 어떻게 반복적 인 IF 기능을 수행 할 수 있습니까 (명령 줄과 같 으세요)? 감사.

내 코드는 다음과 같습니다.

Console.Write("> ");
var Command = Console.ReadLine();
if (Command == "About") {
    Console.WriteLine("This Operational System was build with Cosmos using C#");
    Console.WriteLine("Emerald OS v0.01");
}
도움이 되었습니까?

해결책

string Command;
while (true) {
  Command = Console.ReadLine();
  if (Command == "About") {
    Console.WriteLine("This Operational System was build with Cosmos using C#");
    Console.WriteLine("Emerald OS v0.01");
  }
}

다른 팁

우연히 다음을 의미합니까?

while( !(!(!(( (true != false) && (false != true) ) || ( (true == true) || (false == false) )))) == false   )
   {
       Console.Write("> ");
       if ("About" == Console.ReadLine())
       {
           Console.WriteLine("This Operational System was build with Cosmos using C#");
           Console.WriteLine("Emerald OS v0.01");
       }
   }

귀하의 질문은 불분명하지만 아마도 다음과 같은 일을하고 싶을 것입니다.

while(true) {    //Loop forever
    string command = Console.ReadLine();
    if (command.Equals("Exit", StringComparison.OrdinalIgnoreCase))
        break;    //Get out of the infinite loop
    else if (command.Equals("About", StringComparison.OrdinalIgnoreCase)) {A
        Console.WriteLine("This Operational System was build with Cosmos using C#");
        Console.WriteLine("Emerald OS v0.01");
    }

    //...
}

나는 당신의 질문이 정말 명확하다고 생각하지 않습니다. 그러나 여기에 시도가 있습니다 :)

while (true) {
   if (i ==j ) {
     // whatever
   }
}

이거 말해?

while(true) {
    if( ...) {
    }
}

추신 : 이것은 제가 가장 좋아하는 전처리 업체 해킹 중 하나입니다. C#에서는 작동하지 않지만 C/C ++ 만 작동합니다.

#define ever (;;)

for ever {
    //do stuff
}

나는 당신이 단순한 것을 원한다고 생각합니다 while 하나의 출구 지점이있는 루프.

while(true)
{
    Console.Write("> ");
    var command = Console.ReadLine();
    if (command == "about") {
        Console.WriteLine("This Operational System was build with Cosmos using C#");
        Console.WriteLine("Emerald OS v0.01");
    } else if (command == "exit") {
        break; // Exit loop
    }
}

프로그램이 끝날 때 프로그램이 코드에서 다음 문을 계속 실행하기 때문에 'if'문을 자체적으로 사용할 수 없습니다. 나는 당신이 뒤 따르는 것이 항상 진실로 평가되는 'While'진술이라고 생각합니다.

예를 들어

string Command; 
while(true)
{
    Command = Console.ReadLine(); 
    if (Command == "About")
    { 
        Console.WriteLine("This Operational System was build with Cosmos using C#"); 
        Console.WriteLine("Emerald OS v0.01");
    }
} 

이 루프는 예외가 발생하거나 브레이크 문을 실행하지 않으면 피할 수 없습니다 (또는 동등한 사람이 C#에있는 모든 것이 무엇이든, 나는 Java Guy- 나를 미워하지 마십시오).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top