사용자 도구

사이트 도구


wiki:javascript:javascript_note:js_loop_while

문서의 이전 판입니다!


JavaScript While Loop

  • description : JavaScript While Loop
  • author : 오션
  • email : shlim@repia.com
  • lastupdate : 2021-05-31


the source of this article

The For/Of Loop

Loop는 지정된 조건이 참(true)인 한 코드 블록을 실행할 수 있습니다.

The While Loop

while loop는 지정된 조건이 참(true)인 한 코드 블록을 반복(loop through)합니다.

Syntax

while (condition) {
  // code block to be executed
}

Example

다음 예제에서 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>
/volume1/web/dokuwiki/data/attic/wiki/javascript/javascript_note/js_loop_while.1622425899.txt.gz · 마지막으로 수정됨: 2022/03/10 19:52 (바깥 편집)