title: How to escape a while loop in C#
body: <p>I am trying to escape a while loop. Basically, if the "if" condition is met, I would like to be able to exit this loop:</p>
  
  <pre><code>private void CheckLog()
  {
      while (true)
      {
          Thread.Sleep(5000);
          if (!System.IO.File.Exists("Command.bat"))
              continue;
  
          using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
          {
              string s = "";
              while ((s = sr.ReadLine()) != null)
              {
                  if (s.Contains("mp4:production/CATCHUP/"))
                  {
                      RemoveEXELog();
  
                      Process p = new Process();
                      p.StartInfo.WorkingDirectory = "dump";
                      p.StartInfo.FileName = "test.exe";
                      p.StartInfo.Arguments = s;
                      p.Start();
  
                      &lt;&lt; Escape here - if the "if" condition is met, escape the loop here &gt;&gt;
                  }
              }
          }
      }
  }
  </code></pre>