test.c:12:17: error: break statement not within loop or switch

 

001、

[root@localhost test]# ls
test.c
[root@localhost test]# cat test.c
#include <stdio.h>

int main(void)

{
        int i;
        printf("i = "); scanf("%d", &i);

        if(i > 0)
        {
                puts("greater than 0");
                break;
        }
        else
        {
                puts("less than 0");
        }

        return 0;
}
[root@localhost test]# gcc test.c -o kk
test.c: In function ‘main’:
test.c:12:17: error: break statement not within loop or switch    ## break声明仅仅用于loop和switch语句中
   12 |                 break;
      |                 ^~~~~

 。

 

posted @ 2024-09-19 08:36  小鲨鱼2018  阅读(18)  评论(0编辑  收藏  举报