break语句
#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; }
#include <iostream> using namespace std;int main() {for (int i = 0; i < 10; i++){if (i == 5) {break;}cout << i << endl;}system("pause");return 0; }
#include <iostream> using namespace std;int main() {for (int i = 0; i < 10; i++){for (int j = 0; j < 10; j++) {if (j == 5) {break;}cout << "* ";}cout << endl;}system("pause");return 0; }
continue 语句
如果是奇数输出,偶数不输出
#include <iostream> using namespace std;int main() {for (int i = 0; i <= 100; i++){if (i % 2 == 0) {continue;}cout << i << endl;}system("pause");return 0; }
goto语句
#include <iostream> using namespace std;int main() {cout << "1、xxxxx" << endl;cout << "2、xxxxx" << endl;goto FLAG;cout << "3、xxxxx" << endl;FLAG:cout << "4、xxxxx" << endl;cout << "5、xxxxx" << endl;system("pause");return 0; }