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

多线程循环输出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

推荐的帖子

翻译自: https://www.includehelp.com/cpp-tutorial/looping-find-output-programs-set-2.aspx

多线程循环输出abcc++

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值