加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

(5)C++ 循环

发布时间:2020-12-16 09:15:40 所属栏目:百科 来源:网络整理
导读:? ? 一、for循环 for ( int i = 0 ; i 5 ; i++ ) { cout " abc " endl; } 或 for ( int i = 5 ; i; i-- ) { cout " abc " endl; } ? 二、while循环 int a = 0 ; while (a 10 ) { a ++ ; cout a endl; } ? 三、do while循环 ? int a = 0 ; do { a ++ ; cout a

? ?

一、for循环

    for (int i = 0; i < 5; i++)
    {
        cout << "abc"<< endl;
    }

    for (int i = 5; i; i--)
    {
        cout << "abc" << endl;
    }

?

二、while循环

    int a = 0;
    while (a<10)
    {
        a++;
        cout << a << endl;
    }

?

三、do while循环

?

    int a = 0;
    do
    {
        a++;
        cout << a << endl;
    } while (a<5);

?

四、基于范围 for循环

?对数组或容器类 vector array

    int a[] = { 3,6,8,7 };
    for (int i:a)
    {
        cout << i << endl;
    }

能够修改数组内容

    int a[] = { 3,7 };
    for (int &i:a)
    {
        cout << i << endl;
    }

循环内初始化

    for (int i: { 3,7 })
    {
        cout << i << endl;
    }

?

五、循环和输入

?

?

六、嵌套循环和二维数组

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读