跳轉到內容

Java 程式設計/關鍵字/continue

來自華夏公益教科書,開放的書籍,開放的世界

continue 是一個 Java 關鍵字。它跳過迴圈的剩餘部分,並繼續執行下一個迭代。

例如

Computer code
int maxLoopIter = 7;

for (int i = 0; i < maxLoopIter; i++ ) {
   if (i == 5) {
      continue;  // -- 5 iteration is skipped --
   }
   System.println("Iteration = " + i);
}


結果是

0
1
2
3
4
6
7
華夏公益教科書