1 int func() 2 { 3 printf("In func, before continue.\n"); 4 // continue; 5 break; 6 printf("In func, after continue.\n"); 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從函數里面跳轉出來