This page was translated from English by the community.Learn more and join the MDN Web Docs community.
do...while
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
do...while 문은 테스트 조건이 거짓으로 평가될 때까지 지정된 구문을 실행하는 루프를 만듭니다.단, 구문이 실행된 뒤에 테스트 조건이 평가됨으로 구문은 무조건 한 번은 실행됩니다.
In this article
시도해 보기
let result = "";let i = 0;do { i = i + 1; result = result + i;} while (i < 5);console.log(result);// Expected output: "12345"문법
js
do { statement;} while (condition);예제
>do...while
예제에서do...while 문은 적어도 한번 반복되고 i 변수가 5 보다 작을 때까지 실행됩니다.
js
var result = "";var i = 0;do { i += 1; result += i + " ";} while (i > 0 && i < 5);// Despite i == 0 this will still loop as it starts off without the testconsole.log(result);명세서
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-do-while-statement> |