2014-09-30 77 views
-2

如何在do while語句中添加if-else條件。如果「responseStatus」爲true,我想等待120秒,否則不要做任何事情,並繼續下一個語句。C#:添加if-else in做 - 條件

  bool responseStatus; 

      do 
      { 
       //Do Something 

       responseStatus = IsWaitingForStatus(); 

      } while (if(responseStatus) ? Thread.Sleep(120): do nothing) 

回答

1

它並不真正清楚自己想要什麼,但它聽起來像是你想這樣做:

bool responseStatus; 

// The first call should wait for a specified timeout 
do 
{ 
    responseStatus = IsWaitingForStatus(); 
    if(responseStatus) 
     Thread.Sleep(120) 
    else 
     break; 

} while (true); 
+0

它的工作原理!這是我的預期。另外,修改我的問題一點。 – Uba 2014-09-30 14:13:02