038.程序流程结构-跳转语句-break语句

时间:2021-09-04
本文章向大家介绍038.程序流程结构-跳转语句-break语句,主要包括038.程序流程结构-跳转语句-break语句使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#include <iostream>
using namespace std;
int main()
{
    //break使用

    //1.switch语句中;
    cout << "选择副本难度" << endl;
    cout << "1.普通" << endl;
    cout << "2.中等" << endl;
    cout << "3.困难" << endl;
    int select = 0;
    cin >> select;
    switch (select)
    {
    case 1:
        cout << "你选择是普通难度" << endl;
        break;//退出switch语句
    case 2:
        cout << "你选择是中等难度" << endl;
        break;
    case 3:
        cout << "你选择困难难度" << endl;
        break;
    default:
        break;
    }


    //2.出现在循环语句中;
    for (size_t i = 0; i < 10; i++)
    {
        if (i == 5)
        {
            break;
        }
        cout << i << endl;
    }

    //3.出现在嵌套循环语句中
    for (size_t i = 0; i < 10; i++)
    {
        for (size_t j = 0; j < 10; j++)
        {
            if (j == 5)
            {
                break;//退出内层循环

            }
            cout << "* ";
        }
        cout << endl;
    }

    system("pause");
    return 0;
}

原文地址:https://www.cnblogs.com/ceovs/p/15225830.html