문서의 이전 판입니다!
Loop는 지정된 조건이 참(true)인 한 코드 블록을 실행할 수 있습니다.
while
loop는 지정된 조건이 참(true)인 한 코드 블록을 반복(loop through)합니다.
while (condition) { // code block to be executed }
다음 예제에서 Loop의 코드는 변수 (i)가 10 미만인 한 계속해서 실행됩니다.
<body> <h2>JavaScript While Loop</h2> <p id="demo"></p> <script> var text = ""; var i = 0; while (i < 10) { text += "<br>The number is " + i; i++; } document.getElementById("demo").innerHTML = text; </script> <!-- The number is 0 The number is 1 The number is 2 The number is 3 The number is 4 The number is 5 The number is 6 The number is 7 The number is 8 The number is 9 --> </body>