`do...while` 语句创建一个执行指定语句的循环，直到 `condition` 值为 false。在执行 `statement` 后检测 `condition`，所以指定的 `statement` 至少执行一次。

## 语法

    do
       statement
    while (condition);

`statement`
  执行至少一次的语句，并在每次 `condition` 值为真时重新执行。想执行多行语句，可使用`block`语句（`{ ... }`）包裹这些语句。

`condition`
  循环中每次都会计算的表达式。如果 `condition` 值为真， `statement` 会再次执行。当 `condition` 值为假，则跳到`do...while`之后的语句。

## 示例

### 使用 `do...while`

下面的例子中，`do...while` 循环至少迭代一次，并且继续迭代直到 `i`不再小于 5 时结束。

### HTML 内容

    <div id="example"></div>

### JavaScript 内容

    var result = '';
    var i = 0;
    do {
       i += 1;
       result += i + ' ';
    } while (i < 5);
    document.getElementById('example').innerHTML = result;

### 结果

## 规范

Specification | Status | Comment
--- | --- | ---
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.2
ECMAScript 5.1 (ECMA-262) do-while statement | Standard |
ECMAScript 2015 (6th Edition, ECMA-262) do-while statement | Standard | Trailing ; is now optional.
ECMAScript Latest Draft (ECMA-262) do-while statement | Draft |

## 浏览器兼容

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

| Desktop | Mobile | Server
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js
`do...while` | Chrome Full support Yes | Edge Full support Yes | Firefox Full support 1 | IE Full support 6 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes

### Legend

Full support
  Full support

## 相关链接

- `while`
- `for`