注册 登录
编程论坛 C++教室

怎样在输入错误的时候用break语句跳出for循环?

_Strike 发布于 2016-04-14 17:18, 4578 次点击
#include<stdio.h>
int main()
{
    int i,score;
    printf("input the score:\n");
    for(i=1;i <= 10;i++)
    {
        scanf("%d",&score);
        if(score < 0 && score> 100)
            break;
    }
    return 0;
}
7 回复
#2
_Strike2016-04-14 17:41
就是在满足if条件语句是用break语句跳出for循环
#3
星野2016-04-14 18:06
回复 楼主 _Strike
你的原题是什么呢??
#4
alice_usnet2016-04-14 18:10
#include<stdio.h>
int main()
{
    int i,score;
    printf("input the score:\n");
    for(i=1;i <= 10;i++)
    {
        scanf("%d",&score);
        if(score < 0 || score> 100)  /*这里是逻辑或,没有一个数能同时小于0又大于100,你的逻辑错了*/
            break;
    }
    return 0;
}
#5
_Strike2016-04-14 18:17
噢噢,记错了,问题解决了,谢啦
#6
_Strike2016-04-14 18:19
回复 4楼 alice_usnet
我问一下break不是只能跳出一次循环吗?它跳出了if又跳出for,不是跳了两次?
#7
alice_usnet2016-04-14 20:29
回复 6楼 _Strike
if能算循环吗?
#8
夜泊2016-11-25 16:40
循环指的是for
1