#include <iostream>
using namespace std;
int main (void) {
cout << " 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;
}
Run Code Online (Sandbox Code Playgroud)
嘿所以这段代码产生了一个时间表...我在Google Code的C++类上发现了它...我很困惑为什么每次你经历那个循环时第二个for循环中的"i"重置为1 ...还是在第一个参数中再次声明?
提前致谢!
它"恢复"为1,因为你明确地将它设置为1作为循环的开始条件......
"i"名称在此循环之外不存在,因此每次运行此循环时(对于"c"的每次迭代),"i"是一个新变量,设置为1的开始.