跳轉到內容

JavaScript/保留字/while

來自華夏公益教科書,開放的書籍,開放的世界
上一個: volatile 保留字 下一個: with

Thedo關鍵字

[編輯 | 編輯原始碼]

Thewhile子句包含一個條件,該條件決定何時 do 迴圈結束。

程式碼
  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

另請參閱

[編輯 | 編輯原始碼]
上一個: volatile 保留字 下一個: with
華夏公益教科書