多线程循环输出abcc++

Program 1:

程序1:

#include<iostream>
using namespace std;
int main()
{
for(;;)
{
cout<<"Hello ";
}
return 0;
}

Output:

输出:

Hello Hello .... Infinite loop

Explanation:

说明:

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 loop

Explanation:

说明:

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 Hello

Explanation:

说明:

Here, we declared three local variables i, a, and b with initial values 0, 10, 10 respectively. Here we use a while loop.

在这里,我们声明了三个局部变量iab ,其初始值分别为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相关推荐

  1. 多线程循环输出abcc++_C ++循环| 查找输出程序| 套装4

    多线程循环输出abcc++ Program 1: 程序1: #include <iostream> using namespace std; int A = 5; int fun() { ...

  2. 多线程循环输出abcc++_C ++循环| 查找输出程序| 套装5

    多线程循环输出abcc++ Program 1: 程序1: #include <iostream> using namespace std; int main() { int num = ...

  3. c ++查找字符串_C ++数组| 查找输出程序| 套装5

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { char* STR[] = ...

  4. c ++查找字符串_C ++结构| 查找输出程序| 套装2

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { typedef struct ...

  5. c ++查找字符串_C ++结构| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> #include <math.h> using namespace std; str ...

  6. c ++查找字符串_C ++异常处理| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { try { int num1 ...

  7. c ++查找字符串_C ++结构| 查找输出程序| 套装3

    c ++查找字符串 Program 1: 程序1: #include <iostream> #pragma pack(1) using namespace std; typedef str ...

  8. c ++ 继承_C ++继承| 查找输出程序| 套装1

    c ++ 继承 Program 1: 程序1: #include <iostream> #include <string.h> using namespace std; cla ...

  9. c ++查找字符串_C ++类和对象| 查找输出程序| 套装4

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; int* ...

最新文章

  1. 【Linux】修改/etc/fstab时参数设错,导致启动异常,无法进入系统(已解决)
  2. [windows server 2008 站点系列五]一招加速域用戶的文件查找速度
  3. 链表问题8——将单向链表按某值划分成左边小、中间相等、右边大的形式(初阶)
  4. appium学习【二】:用try捕获异常后,用例的执行结果为pass
  5. ajax 遍历select 下拉框
  6. 090_块元素行内元素行内块元素空元素
  7. 使用diskpart命令为windows7创建分区
  8. POJ 2955 区间DP必看的括号匹配问题,经典例题
  9. 分析FLV文件分析和解析器的开源代码
  10. html判断整数小数点后两位小数点,js控制input框只能输入数字和一位小数点且小数点后面只有两位小数...
  11. python 处理CSV数据
  12. 什么是C ??!??!操作员呢?
  13. Swift面向对象基础(中)——Swift中的方法
  14. 字节跳动正式offer之前是哪一个环节_不是做梦!她在3天前拿到腾讯、百度、字节跳动的offer!...
  15. oracle现金流量表逻辑,分析现金流量表填列法的逻辑
  16. 沃商店运营一周年凸显平台化优势
  17. HTML小说排行榜案例
  18. 零极限:创造健康、平静与财富的四句话
  19. vue 3.0学习1
  20. 微信小程序原生表格组件

热门文章

  1. android gridview滚动条位置,Android GridView滚动到指定位置
  2. Scala的控制结构
  3. 计数排序与桶排序python实现
  4. matlab2016b ubuntu命令行安装 + matconvnet的安装
  5. PHP与ThinkPHP读写文件
  6. 如何在路由器的局域网下使用IIS发布网页
  7. iOS7时代我们用什么来追踪和识别用户?
  8. Windows Phone 7开发一月谈(3)
  9. 让sky Driver成为你的可见硬盘
  10. Silverlight 解谜游戏 之十六 消失的蒙娜丽莎