for (循环变量赋初值; 循环条件; 循环变量增值) { 语句; // 循环体 ...... }
例:
for(int i=0; i<100; i++) { cout<<i; }
for 循环执行过程
for (i = 1; i <= 10; ) cout << 1 << " "; i = i + 1; for (2 <= 10; ) cout << 2 << " "; i = i + 1; //i = 3 for (3 <= 10; ) cout << 3 << " "; i = i + 1; //i = 4 for (4 <= 10; ) cout << 4 << " "; i = i + 1; //i = 5 ...... for (9 <= 10; ) cout << 9 << " "; i = i + 1; //i = 10 for (10 <= 10; ) cout << 10 << " "; i = i + 1; //i = 11 for (11 <= 10; ) X
共 11 条回复
for 循环执行过程