初始化
do{
}while(判断);
int scores[]={123,5,6,8,4,25,69}
for(int temp:scores){
cout<<temp;scores
}
for 使用定义临时变量temp 读取数组里的每个yuan's
初始化
do{
}while(判断);
int scores[]={123,5,6,8,4,25,69}
for(int temp:scores){
cout<<temp;scores
}
for 使用定义临时变量temp 读取数组里的每个yuan's
do{循环体} while(判断) while先执行判断
do先执行循环体
生疏
C++11的新遍历方式:
for(int 临时变量 : 数组)
{
}
#include <iostream>
using namespace std;
int main()
{
//do {
// // 循环体
//} while (判断);
int i = 100;
//do
//{
// cout << "创建敌人" << endl;
//} while (i>100);
// do while 循环体次数 >=1 的
//while (i>100)
//{
// cout << "创建敌人" << endl;
//}
// while 循环体次数 >=0 的
int scores[] = { 234,2,42,3,2,42,42,32 };
//for (int i = 0; i < 8; i++)
//{
// cout << scores[i] << endl;
//}
// C++11的标准
//for (int temp : scores)
//{
// //cout << temp << endl;
// temp = 10; // 笔记:不起作用
//}
//for (int temp : scores)
//{
// cout << temp << endl;
//}
for (int& temp : scores) // 注意:int& temp
{
//cout << temp << endl;
temp = 10;// temp = temp * 2; // 起到作用了,因为 int & temp,引用类型
}
for (int temp : scores)
{
cout << temp << endl;
}
return 0;
}