打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
continue与break
continue 与 break都常用于用于循环体中,而且continue只用于循环体中,break还可以用于switch中。
下面示例循环中的区别:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{

    while(1) {
        int tmp;
        printf("begin while\n");
        scanf("%d",&tmp);
        if(tmp!=3) continue;  //退出本次循环,继续重新开始循环,并忽略所有后面的代码
        else {printf("input tmp:%d\n",tmp); break; } //退出循环
    }

    return 0;

}

运行结果:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{

    while(1) {
        int tmp;
        printf("begin while\n");
        scanf("%d",&tmp);
        if(tmp!=3) continue;  //退出本次循环,继续重新开始循环,并忽略所有后面的代码
        else  break;  //退出循环
        printf("input tmp:%d\n",tmp);
    }

    return 0;

}

运行结果:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
if跟for循环语句的知识点
循环里continue,break,return的作用,你知道吗?
同时被3 5 7整除的就输出
深入c语言continue和break的区别详解
第六章 循环控制
c语言代码例题
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服