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

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;
}
相关推荐
陈天伟教授5 小时前
基于学习的人工智能(7)机器学习基本框架
人工智能·学习
Ccjf酷儿5 小时前
操作系统 蒋炎岩 3.硬件视角的操作系统
笔记
习习.y5 小时前
python笔记梳理以及一些题目整理
开发语言·笔记·python
Z***G4796 小时前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
爬虫·学习·计算机外设
在逃热干面6 小时前
(笔记)自定义 systemd 服务
笔记
我命由我123457 小时前
微信开发者工具 - 模拟器分离窗口与关闭分离窗口
前端·javascript·学习·微信小程序·前端框架·html·js
DKPT7 小时前
ZGC和G1收集器相比哪个更好?
java·jvm·笔记·学习·spring
Main. 248 小时前
从0到1学习Qt -- 常见控件之显示类控件
qt·学习
e***19358 小时前
爬虫学习 01 Web Scraper的使用
前端·爬虫·学习
QT 小鲜肉9 小时前
【孙子兵法之上篇】001. 孙子兵法·计篇
笔记·读书·孙子兵法