웹 프로그래밍 기초/반복문
do while문
별초롱언니
2025. 4. 3. 14:30
01. 개념
먼저 반복문을 1차 실행한 후에 조건식에 의해 반복 여부를 체크한다. 나머지 기능은 while문과 동일하다.
02. 사용법
do {
// 반복할 구문
} while (조건식);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var i = 0;
var array01 = ["사과","배","포도","천혜향","레몬","딸기","복숭아","오렌지","자몽"];
do {
document.write(array01[i] + "<br>");
i++;
} while (i < -1);
</script>
</body>
</html>