C++自学计划-循环-09

2018-12-17  本文已影响0人  你缺少想象力

1.while

例子:

    int a = 10;
    int b = 20;
    while (b > a) {
        a += 1;
        std::cout << a << std::endl;
    }

2.do...while

int a = 10;
    int b = 20;

    do {
        a += 1;
        std::cout << a << std::endl;
    } while (b > a);

3.for

for (int i = 0; i < 10; ++i) {
        std::cout << i << std::endl;
}
上一篇 下一篇

猜你喜欢

热点阅读