[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/while [Back]  [Original]

while - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

while

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.

while truewhile

js
while (condition)
  statement

false statement

statement true statement false while

{ ... }

In this article

1

while n 3

js
n = 0;
x = 0;
while (n < 3) {
  n++;
  x += n;
}

n n xx n

  • n = 1x = 1
  • n = 2x = 3
  • n = 3x = 6

n < 3 true

2

false while false

js
while (true) {
  alert("Hello, world");
}

Web Proxy Viewer  |  New URL  |  Original Page