c++代码疑问for循环条件表达式第一个表达式的疑问
1 #include <iostream> 2 using namespace std; 3 int main(){ 4 int i=0,j=0; 5 for(;i<10;i++){ 6 for(;j<10;j++)
{//明显这个循环只执行了一次 7 cout<<"*"; 8 } 9 cout<<endl; 10 } 11 12 system("pause"); 13 }
运行结果:
* * * * * * * * * *
请按任意键继续. . .
代码
1 #include <iostream> 2 using namespace std; 3 int main(){ 4 5 for(int i=0;i<10;i++){ 6 for(int j=0;j<10;j++) 7 {//明显这个循环执行了10次 8 cout<<"*"; 9 } 10 cout<<endl; 11 } 12 13 system("pause"); 14 }
运行结果
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 请按任意键继续. . .
对于for循环再条件第一个表达式空和声明表达式时,出现不同的结果,不知什么原因。
以上代码在Microsoft Visual C++ 2019上编译


浙公网安备 33010602011771号