循环for do while continue break,达夫设备

1. while()为了反复执行循环体

2. do{}while()宏定义使用比较多

3. for为了限制循环次数,使结果更加明确

4. break跳出循环语句,只能跳出一层循环

5. continue继续下一次循环,为了节约时间

示例代码:

#include<iostream>

using namespace std;

int main()
{
    int count = 0;
    //while为了反复执行循环体
    while (count > 0)
    {

    }

    do   //宏定义用的比较多
    {
        count++;
    } while (count < 10);
        
    cout << count;
    //for为了限制循环次数,使结果更加明确
    for (int i = 0; i < 5; i++)
    {
        cout << i;
    }

    while (1)
    {
        count++;
        if (count > 9)
            break;  //跳出循环语句,只能跳出一层循环
    }


    //continue 为了节约时间
    int j = 0;
    for (; j < 10; j++)
    {
        if (j % 2 == 0)
            continue;
        cout << j;
    }
    return 0;
}

达夫设备

转载:达夫设备Duff's Device

原文地址:https://www.cnblogs.com/mmmmmmmmm/p/14319620.html