C++ 非常简单的c++;对于声明,但它不能?
我的问题很简单。我在c++程序中有一个“for”语句,编译时会忽略我的cout 我正在使用xcode,使用xcode编译,下面是我的代码:C++ 非常简单的c++;对于声明,但它不能?,c++,xcode,for-loop,cout,C++,Xcode,For Loop,Cout,我的问题很简单。我在c++程序中有一个“for”语句,编译时会忽略我的cout 我正在使用xcode,使用xcode编译,下面是我的代码: #include <iostream> using namespace std; int main () { cout << this prints" << endl; for(int i=0; i>10; i++) { cout <&
#include <iostream>
using namespace std;
int main ()
{
cout << this prints" << endl;
for(int i=0; i>10; i++)
{
cout << "this doesn't" << endl;
}
return 0;
}
#包括
使用名称空间std;
int main()
{
库特
您将i
初始化为0
,然后仅当i
大于10
时才进入循环体
只要条件i>10
为真,循环就会循环,直到条件i>10
为真。这就是C++中所有循环的工作方式:for
,while
,和do/while
您的循环条件是向后的。您希望它是i<10
您已经得到了l的条件oop不正确。这应该可以工作。请检查以下内容:
#include <iostream>
using namespace std;
int main ()
{
cout << "this prints" << endl;
for(int i=0; i<= 10; i++) // ------> Check the change in condition here
{
cout << "this doesn't" << endl;
}
return 0;
}
#包括
使用名称空间std;
int main()
{
库特
#include <iostream>
using namespace std;
int main ()
{
cout << "this prints" << endl;
for(int i=0; i<= 10; i++) // ------> Check the change in condition here
{
cout << "this doesn't" << endl;
}
return 0;
}