for
语法:
for( initialization; test-condition; increment ) { statement-list; } |
for构造一个由4部分组成的循环:
- 初始化, 可以由0个或更多的由逗号分开的初始化语句构成;
- 判断条件,如果满足该语句循环继续执行;
- 增量, 可以由0个或更多的由逗号分开的增量语句构成;
- 语句体,由0个或更多的语句构成,当循环条件成立时他们被执行.
for( int i = 0; i < 10; i++ ) { cout << "i is " << i << endl; } int j, k; for( j = 0, k = 10; j < k; j++, k-- ) { cout << "j is " << j << " and k is " << k << endl; } for( ; ; ) { // loop forever! }
标签:语句,20221022,C++,逗号,循环,1900 From: https://www.cnblogs.com/jyssh/p/16817095.html