多线程循环输出abcc++_C ++循环| 查找输出程序| 套装2
多線程循環輸出abcc++
Program 1:
程序1:
#include<iostream> using namespace std;int main() { for(;;){cout<<"Hello ";}return 0; }Output:
輸出:
Hello Hello .... Infinite loopExplanation:
說明:
In the above code, the loop will execute infinitely. In C++, if we did not mention any condition in the loop then I will consider it as a true. Then the condition will never false, so the loop will never terminate. Then the "Hello" will print infinite times on the console screen.
在上面的代碼中,循環將無限執行。 在C ++中,如果我們在循環中沒有提及任何條件,那么我將其視為真實情況。 然后條件將永遠不會為假,因此循環將永遠不會終止。 然后,“ Hello”將在控制臺屏幕上無限次打印。
Program 2:
程式2:
#include <iostream> using namespace std;int main() {for (; EOF;) {cout << "Hello ";}return 0; }Output:
輸出:
Hello Hello .... Infinite loopExplanation:
說明:
In the above code, the loop will execute infinitely. In the above code w mentioned EOF in place of loop condition, In C++, EOF is a predefined MACRO, the value of EOF is -1. And as we know that, In C++ any non-zero value is considered as a true for conditions. so the loop will never terminate. Then the "Hello" will print infinite times on the console screen.
在上面的代碼中,循環將無限執行。 在上面的代碼w中,提到了EOF代替循環條件,在C ++中, EOF是預定義的MACRO, EOF的值為-1。 眾所周知,在C ++中,對于條件,任何非零值都被認為是正確的。 因此循環永遠不會終止。 然后, “ Hello”將在控制臺屏幕上無限次打印。
Program 3:
程式3:
#include <iostream> using namespace std;int main() {int i = 0;int a = 10, b = 10;while (a > b ? 0 : 1) {i++;cout << "Hello ";if (i > 2)break;}return 0; }Output:
輸出:
Hello Hello HelloExplanation:
說明:
Here, we declared three local variables i, a, and b with initial values 0, 10, 10 respectively. Here we use a while loop.
在這里,我們聲明了三個局部變量i , a和b ,其初始值分別為0、10、10。 在這里,我們使用一個while循環。
Let's understand the condition of a while loop.
讓我們了解while循環的條件。
while(a>b?0:1)In the while loop, we used a ternary operator, here condition (10>10)? is false then it returns 1, so the condition for while loop will be true always.
在while循環中,我們使用了三元運算符,此處條件(10> 10)為false,然后返回1,因此while循環的條件始終為true。
In the body of the while loop we used a counter variable i and cout<<"Hello " to print "Hello " on the console.
在while循環的主體中,我們使用了計數器變量i和cout <<“ Hello”在控制臺上打印“ Hello” 。
Here "Hello " will be printed 3 times, because the loop will terminate when the value of the variable i becomes 3 that is greater than 2.
此處“ Hello”將被打印3次,因為當變量i的值變為大于2的3時,循環將終止。
Recommended posts
推薦的帖子
C++ Looping | Find output programs | Set 1
C ++循環| 查找輸出程序| 套裝1
C++ Looping | Find output programs | Set 3
C ++循環| 查找輸出程序| 套裝3
C++ Looping | Find output programs | Set 4
C ++循環| 查找輸出程序| 套裝4
C++ Looping | Find output programs | Set 5
C ++循環| 查找輸出程序| 套裝5
C++ Operators | Find output programs | Set 1
C ++運算符| 查找輸出程序| 套裝1
C++ Operators | Find output programs | Set 2
C ++運算符| 查找輸出程序| 套裝2
C++ const Keyword | Find output programs | Set 1
C ++ const關鍵字| 查找輸出程序| 套裝1
C++ const Keyword | Find output programs | Set 2
C ++ const關鍵字| 查找輸出程序| 套裝2
C++ Reference Variable| Find output programs | Set 1
C ++參考變量| 查找輸出程序| 套裝1
C++ Reference Variable| Find output programs | Set 2
C ++參考變量| 查找輸出程序| 套裝2
C++ Conditional Statements | Find output programs | Set 1
C ++條件語句| 查找輸出程序| 套裝1
C++ Conditional Statements | Find output programs | Set 2
C ++條件語句| 查找輸出程序| 套裝2
C++ Switch Statement | Find output programs | Set 1
C ++轉換語句| 查找輸出程序| 套裝1
C++ Switch Statement | Find output programs | Set 2
C ++轉換語句| 查找輸出程序| 套裝2
C++ goto Statement | Find output programs | Set 1
C ++ goto語句| 查找輸出程序| 套裝1
C++ goto Statement | Find output programs | Set 2
C ++ goto語句| 查找輸出程序| 套裝2
翻譯自: https://www.includehelp.com/cpp-tutorial/looping-find-output-programs-set-2.aspx
多線程循環輸出abcc++
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的多线程循环输出abcc++_C ++循环| 查找输出程序| 套装2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中get接口示例_Java Lo
- 下一篇: Java即时类| hashCode()方