반복문 while
(Loop)
1. while
조건문이 true에서 false가 될 때까지 반복
while(조건){
반복해서 실행할 코드;
}
예시) 2와 3을 세 번 반복시키고 싶을 때

<h1>Loop</h1>
<ul>
<script>
document.write('<li>1</li>');
var i = 0; //1) i는 현재 0
while(i < 3){ //2) 현재 0인 i는 < 3 ture 이므로
document.write('<li>2</li>'); //3) 2와 3이 첫번째 반복되어 출력된다.
document.write('<li>3</li>');
i = i + 1;
}
document.write('<li>4</li>');
</script>
</ul>
Last updated
Was this helpful?