2017-03-27 78 views
0

我是C++的新手,在學習C++之前我已經學過了pascal。我必須繼續重複輸入過程,直到滿足這個條件(1 <= m <= n <= 1000000000, n-m<=100000)pascal,使用「repeat ... until」命令很容易,但在C++中只有「while」只在條件爲假時才停止如何創建一個不會停止,直到條件滿足的循環

+1

使用'而(yourCondition!)' – Hugal31

+5

'do {...} while(condition)'將C++等同於'repeat ... until'。 – acraig5075

+0

並注意,在'while'和'until'中''condition'會產生相反的效果 - 決定是繼續還是停止。 –

回答

1

只要把你的條件,while循環分隔每個條件與& &如果你想兩個條件導致真:

試試這個:

while(!(m>=1 && n>=1 && n<=1000000000 && (n-m) <=100000)){ 

    // your code here 

    } 
+0

這將不會退出循環,除非在閉合大括號之前更改了一個或多個指定的變量。 –

0
while(true){ 

    if(m>=1 && n>=1 && n<=1000000000 && (n-m) <=100000) 
    break; 
    // do something 

} 
+3

我不會使用'while(true)'。這是一個壞習慣,這讓我很多時候都感到煩惱。 – gvlachakis

相關問題