Board logo

標題: continue、break、return (二) [打印本頁]

作者: 鄭繼威    時間: 2024-1-3 18:06     標題: continue、break、return (二)

break 語法能強制程序立即跳出所在迴圈。
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=1; i<=10; i++)
  7.     {
  8.         if(i==5)
  9.             break;
  10.         cout<<i<<endl;
  11.     }
  12.     for(int i=1; i<=10; i++)
  13.     {
  14.         cout<<i<<endl;
  15.     }
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2