c_cpp for循环

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp for循环相关的知识,希望对你有一定的参考价值。

#include <iostream>

using namespace std;

int main() {
	

	//Logical Operators - make complex conditions
	//! -  NOT operator
	//&& - AND operator
	//|| - OR operator

	int var1 = 1000;
	if (!(var1 == 100)) //Opposite of the condition
	{
		cout << "Variable is not equal to 100" << endl;
	}

	if (var1 == 1000 && var1 > 10) //Both conditions have to be true
	{
		cout << "Both conditions were satisfied" << endl;
	}

	string name;
	cout << "Give us a name: " << endl;
	cin >> name;
	if (name == "Bobby" || name == "Jerry") //Only one condition has to be true
	{
		cout << "You chose one of the special names" << endl;
	}

	//Even more complex
	//Ask for an age too
	int age;
	cout << "Give us an age too: ";
	cin >> age;
	if ((name == "Bobby" || name == "Jerry") && age > 18)
	{
		cout << "You met the requirements" << endl;
	}
	else {
		cout << "Wrong info!" << endl;
	}


	return 0;
}

以上是关于c_cpp for循环的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 这个简单的代码片段显示了如何使用有符号整数在C中完成插值。 for()循环确定要插入的范围

c_cpp 检测链表中循环或循环的起始节点

c_cpp 循环链接清单实施

c_cpp 对于循环

c_cpp 无限循环1

c_cpp 循环