跳转语句(个人学习笔记黑马学习)

break语句

cpp 复制代码
#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;
}

cpp 复制代码
#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;
}

cpp 复制代码
#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 语句

如果是奇数输出,偶数不输出

cpp 复制代码
#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语句

cpp 复制代码
#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;
}
相关推荐
人生游戏牛马NPC1号1 小时前
学习 Flutter (三):玩安卓项目实战 - 上
android·学习·flutter
还债大湿兄1 小时前
《C++内存泄漏8大战场:Qt/MFC实战详解 + 面试高频陷阱破解》
c++·qt·mfc
深圳卢先生4 小时前
CentOS 安装jenkins笔记
笔记·centos·jenkins
u_topian4 小时前
【个人笔记】Qt使用的一些易错问题
开发语言·笔记·qt
没有羊的王K5 小时前
SSM框架学习——day1
java·学习
珊瑚里的鱼5 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
AI+程序员在路上5 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变
开发语言·c++·qt
Risehuxyc5 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果
开发语言·c++
林林要一直努力6 小时前
AOSP Settings模块问题初窥
android·学习·bug·android studio
景彡先生8 小时前
C++编译期计算:常量表达式(constexpr)全解析
服务器·c++