Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 循环/while循环背后的逻辑_C++_Loops - Fatal编程技术网

C++ 循环/while循环背后的逻辑

C++ 循环/while循环背后的逻辑,c++,loops,C++,Loops,我需要帮助理解while循环/for循环之间的逻辑差异以下是示例代码: #include<iostream> using namespace std; int main(void) { cout << "A multiplication table:" << endl << " 1\t2\t3\t4\t5\t6\t7\t8\t9" << endl << "" << endl; f

我需要帮助理解while循环/for循环之间的逻辑差异以下是示例代码:

#include<iostream>
 using namespace std;

int main(void)
{
 cout << "A multiplication table:" << endl
      << "  1\t2\t3\t4\t5\t6\t7\t8\t9" << endl
      << "" << endl;
 for(int c = 1; c < 10; c++)
 {
      cout << c << "| ";
      for(int i = 1; i < 10; i++)
      {
      cout << i * c << '\t';
      }
      cout << endl;
 }
 return 0;
}
#包括
使用名称空间std;
内部主(空)
{

cout在这两个示例中,您必须设置i=1才能获得预期的行为。对于for循环,这已经得到了处理,因为在for循环的头中,有一个for(int i=1;…;…)

#include <iostream>
using namespace std;


int main() {
  int i = 1;
int c = 1;
while (c< 10){
    cout << c <<"|";
    c++;
    while (i< 10){
        cout << i * c << '\t';
        i++;


    }
    cout << endl;
}

cin.clear();
cin.ignore();
cin.get();

return 0;
}
for (i=0;i<n;i++) {
     dosomething;
}
i=0;
while (i<n) {
   dosomething;
   i++;
}
#include <iostream>
using namespace std;


int main() {
int c = 1;
while (c< 10){
    cout << c <<"|";
    c++;
    int i=1;
    while (i< 10){
        cout << i * c << '\t';
        i++;


    }
    cout << endl;
}

cin.clear();
cin.ignore();
cin.get();

return 0;
}