break使用的时机:
1。出现在switch条件语句中,作用是终止case并跳出switch
2。出现在循环语句中,作用是跳出当前的循环语句
3。出现在嵌套循环中,跳出最近的内层循环语
示例一:
#include<iostream>
using namespace std;
int main()
{
cout << "请选择副本难度" << endl;
cout << "1、普通" << endl;
cout << "2、中等" << endl;
cout << "3、困难" << endl;
int select = 0;
cin >> select;
switch (select)
{
case 1:
cout << "你选择的是普通难度" << endl;
break;
case 2:
cout << "你选择的是中等难度" << endl;
break;
case 3:
cout << "你选择的是困难难度" << endl;
break;
default:
break;
}
system("pause");
return 0;
}
运行结果如下——