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 July 2015.
do...while
문은 테스트 조건이 거짓으로 평가될 때까지 지정된 구문을 실행하는 루프를 만듭니다.
단, 구문이 실행된 뒤에 테스트 조건이 평가됨으로 구문은 무조건 한 번은 실행됩니다.
시도해보기
let result = "";
let i = 0;
do {
i = i + 1;
result = result + i;
} while (i < 5);
console.log(result);
// Expected output: "12345"
문법
예제
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 test
console.log(result);
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-do-while-statement |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
do...while |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.