break语句
#include<iostream>
using namespace std;
#include<string>
#include<ctime>
int main() {
//2010年4月
/*
break:用于跳出选择结构、循环结构
1,出现在循环语句中,跳出当前循环
2,出现在嵌套循环语句中,跳出最近的内层循环语句
3,出现在switch条件语句中,作用是终止case并跳出switch
*/
for (int i = 1;i <= 10;i++) {
if (i == 6) {
break;
}
cout << i << endl;
}
cout << "请选择游戏难度:1初级,2中级,3高级" << endl;
int select = 0;
cin >> select;
switch(select) {
case 1:
cout << "你选择的是初级难度" << endl;
break;//终止,跳出选择
case 2:
cout << "你选择的是中级难度" << endl;
break;
default:
cout << "高级难度" << endl;
break;
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (j == 3) {
break;
}
cout << "#";
}
cout << endl;
}
system("pause");
return 0;
}