C++入门学习(二十七)跳转语句—break语句

1、与switch语句联合使用

C++入门学习(二十三)选择结构-switch语句-CSDN博客

#include <iostream>  
#include <string>
using namespace std;
  
int main() {  
 
int number;
 
cout<<"请为《斗萝大路》打星(1~5※):" <<endl; 
cin>>number;
switch (number) {
	case 1:
		cout<<"*"<<endl; 
		break; 
	case 2:
		cout<<"**"<<endl; 
		break;
	case 3:
		cout<<"***"<<endl; 
		break;
	case 4:
		cout<<"****"<<endl;
		break; 
	case 5:
		cout<<"*****"<<endl; 
		break;
	default:
		cout<<"没有这个分数"<<endl;
	 
	
	} 
 
return 0; 
 
}

如果没有break,会产生怎样的效果呢?我将上述代码中的break都删除一了,看一下结果吧: 

2、与for循环结合起来

C++入门学习(二十六)for循环-CSDN博客

#include <iostream>  
using namespace std;
int main() {  
    for (int i = 1; i <= 10; i++) {  
         if (i==6)
		{
			cout<<"666"<<endl;
			break;
		 }  
        cout <<i<<endl;  
      
    }  
    return 0;  
}

相关推荐

  1. C++入门学习三)选择结构-switch语句

    2024-02-14 03:18:01       58 阅读
  2. [C++基础学习]----03-程序流程结构之语句详解

    2024-02-14 03:18:01       31 阅读
  3. C++循环嵌套和break语句

    2024-02-14 03:18:01       56 阅读
  4. C语言经典面试题目(

    2024-02-14 03:18:01       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-14 03:18:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-14 03:18:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-14 03:18:01       82 阅读
  4. Python语言-面向对象

    2024-02-14 03:18:01       91 阅读

热门阅读

  1. 【个人笔记】计算机网络五层结构理解

    2024-02-14 03:18:01       43 阅读
  2. 前端架构: 简易版脚手架开发

    2024-02-14 03:18:01       54 阅读
  3. 2024/2/8

    2024-02-14 03:18:01       44 阅读
  4. <s-table>、<a-table>接收后端数据

    2024-02-14 03:18:01       48 阅读
  5. 【无标题】

    2024-02-14 03:18:01       42 阅读
  6. 水题中的稀奇古怪trick合集

    2024-02-14 03:18:01       58 阅读