continue 編集

continueキーワードは、ループ文を直ちに中断し、あたかもループが最後まで終了したかのように開始行に進み、for文の場合は第三項を評価します。 ループ文以外でcontinueを使おうとすると SyntaxError となります。 ここで言うループ文は、while文、do文、for文、for-in文、for-of文のいずれかです。 Array.prototype.forEachの様な反復メソッドにはcontinueは使えません。

例題 編集

const array = [2, 3, 5, 7, 10, 11];
let result = 1;
for (let i = 0, len = array.length; i < len; i++) {
  result += array[i];
  if (result % 2 == 0) {
    continue;
  }
  console.log("result = " + result);
}

実行結果

result = 3
result = 11
result = 39

関連項目 編集