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

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;
}
相关推荐
OrangeJiuce11 分钟前
【QT中的一些高级数据结构,持续更新中...】
数据结构·c++·qt
东方芷兰1 小时前
伯克利 CS61A 课堂笔记 11 —— Mutability
笔记·python
程序员-King.3 小时前
【接口封装】——13、登录窗口的标题栏内容设置
c++·qt
萌の鱼3 小时前
leetcode 2826. 将三个组排序
数据结构·c++·算法·leetcode
RAN_PAND4 小时前
STL介绍1:vector、pair、string、queue、map
开发语言·c++·算法
mit6.8246 小时前
[实现Rpc] 通信-Muduo库的实现 | && 完美转发 | reserve | unique_lock
c++·网络协议·rpc
快下雨了L7 小时前
C++面试笔记(持续更新...)
笔记
陈无左耳、7 小时前
HarmonyOS学习第3天: 环境搭建开启鸿蒙开发新世界
学习·华为·harmonyos
柃歌7 小时前
【UCB CS 61B SP24】Lecture 7 - Lists 4: Arrays and Lists学习笔记
java·数据结构·笔记·学习·算法