跳轉到內容

JavaScript/保留字/do

來自華夏公益教科書,自由的教科書
上一頁: delete 保留字 下一頁: double

Thedo關鍵字

[編輯 | 編輯原始碼]

Thedo … while語句執行迴圈,直到在 while 語句中達到條件。

程式碼
  var array = [2, 3, 5, 7, 10, 11], i = 0, result = 1;

  do {
    result += array[i++];
	
    if (result%2 == 0) {
      continue;
    } else if (result > 20) {
      break;
    } else {
      console.log("result = " + result);
    }
  } while (i < array.length)
返回以下內容
result = 3
result = 11
上一頁: delete 保留字 下一頁: double
華夏公益教科書