break和continue能否跳出函数

 1 int func()
 2 {
 3     printf("In func, before continue.
");
 4 //    continue;
 5     break;
 6     printf("In func, after continue.
");
 7 }
 8 int main()
 9 {
10     func();
11     return 0;
12 }

第4、第5行分别注释, 来编译看看:

[zyc@localhost personalCode]$ vim tmp.c
[zyc@localhost personalCode]$ gcc tmp.c
tmp.c: In function ‘func’:
tmp.c:5:2: error: continue statement not within a loop
  continue;
  ^
[zyc@localhost personalCode]$ vim tmp.c
[zyc@localhost personalCode]$ gcc tmp.c
tmp.c: In function ‘func’:
tmp.c:6:2: error: break statement not within loop or switch
  break;
  ^

我只翻译上面报错的两句:

error: continue语句不在一个循环里

error: break语句不在一个循环或者选择(语句)里

可见,不能用break或者continue从函数里面跳转出来

原文地址:https://www.cnblogs.com/fallenmoon/p/8779267.html