一、for循环 for ( int i = 0 ; i 5 ; i++ ) { cout " abc " endl; } 或 for ( int i = 5 ; i; i-- ) { cout " abc " endl; } 二、while循环 int a = 0 ; while (a 10 ) { a ++ ; cout a endl; } 三、do while循环 int a = 0 ; do { a ++ ; cout
一、for循环
for (int i = 0; i < 5; i++) { cout << "abc"<< endl; }
或
for (int i = 5; i; i--) { cout << "abc" << endl; }
二、while循环
int a = 0; while (a<10) { a++; cout << a << endl; }
三、do while循环
int a = 0; do { a++; cout << a << endl; } while (a<5);
四、基于范围 for循环
对数组或容器类 vector array
int a[] = { 3,6,8,7 }; for (int i:a) { cout << i << endl; }
能够修改数组内容
int a[] = { 3,6,8,7 }; for (int &i:a) { cout << i << endl; }
循环内初始化
for (int i: { 3,6,8,7 }) { cout << i << endl; }
五、循环和输入