C语言之break和continue

break:cause the innermost enclosing loop or switch to be exited immediately.
continue: cause the next iteration of the enclosing for, while, or do loop to begin. The continue statement applies only to loops, not to switch. A continue inside a switch inside a loop causes the next loop iteration.

break:导致最内层的封闭循环或者switch立刻退出;
continue:导致for,while,或者do循环的下一个循环开始执行。continue只用在循环中,不用在switch中。一个循环中switch中的continue会导致下一个循环。
#include <stdio.h>

/* test the break and continue */
int main()
{
    int i;
    for (i = 0; i < 10; i++)
    {
        switch(i)
        {
            case 5:
                break;
        }
        printf("%d", i);
    }
    return 0;
}
输出:0 1 2 3 4 5 6 7 8 9
break只是退出了switch,执行了后面的printf

#include <stdio.h>

/* test the break and continue */
int main()
{
    int i;
    for (i = 0; i < 10; i++)
    {
        switch(i)
        {
            case 5:
                continue;
        }
        printf("%d", i);
    }
    return 0;
}
输出:0 1 2 3 4 6 7 8 9
continue直接执行下一个for循环,没有执行printf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值