• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>JavaScript Iteration Statement</title>
7
</head>
8
​
9
<body>
10
​
11
    <h1>while 문</h1>
12
​
13
    <script>
14
        var i = 1;
15
        
16
        while (i < 10) { // 변수 i가 10보다 작을 때만 while 문을 반복함.
17
            document.write(i + "<br>");
18
            i++; // 반복할 때마다 변수 i를 1씩 증가시켜 변수 i가 10보다 커지면 반복문을 종료함.
19
        }
20
    </script>
21
    
22
</body>
23
​
24
</html>