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

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;
}
相关推荐
kkk_皮蛋21 分钟前
力扣773:滑动谜题
c++
哦豁灬38 分钟前
NCNN 学习(2)-Mat
深度学习·学习·ncnn
Length-vision40 分钟前
Linux入门学习:Linux调试器gdb使用
linux·学习
float_com1 小时前
【STL】 set 与 multiset:基础、操作与应用
c++·stl
茶馆大橘2 小时前
(黑马点评)八、实现签到统计和uv统计
数据库·redis·学习·阿里云·黑马点评
临沂堇2 小时前
CCF刷题计划——训练计划(反向拓扑排序)
数据结构·c++·算法·拓扑·ccf
铁匠匠匠2 小时前
【C总集篇】第八章 数组和指针
c语言·开发语言·数据结构·经验分享·笔记·学习·算法
猿饵块2 小时前
cmake--get_filename_component
java·前端·c++
森龙安2 小时前
string类,vector<T>,iterator迭代器,C风格字符串,数组
c++
秋邱2 小时前
C++: 类和对象(上)
开发语言·c++