[TIL]왕초보탈출기#7 반복문

BINGBING🐨·2021년 4월 27일
0

Javascript

목록 보기
7/21

반복문?

컴퓨터를 강려크하게 만드는 반복문에 대해 공부한 내용

while문

while(조건)/*조건은 Boolean*/{
	반복해서 실행할 코드 입력
} /*조건이 true에서 false가 될 때까지 실행한다.*/
<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            var i = 0;//i 값 정의
            while(i < 10){ //i가 10보다 작을때 까지
                document.write("Coding errbody <br />");
                i = i + 1; //i를 1씩 반복해서 더한다.
            }

        </script>
    </body>
</html>

for문

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
           /* while문 */
          /* var i = 0;//i 값 정의
            while(i < 10){ //i가 10보다 작을때 까지
                document.write("Coding errbody <br />");
                i = i + 1; //i를 1씩 반복해서 더한다.
            } */
                          /* for 문 */
              for(var i = 0; i < 10; i++){
              document.write("Coing errbpdy " + i<br />);
          } 
          // while문과 같은 결과가 나타난다.
         
        </script>
    </body>
</html>

break

for ~ if
break는 반복문을 중단(완전종료)시키는 제어문이다.
반대로 continu는 (false만 제외하고)반복문을 계속 이어나가는 제어문이다.
조건문안에, 반복문이 / 반복문안에 조건문이 들어갈 수 있다!

profile
iOS Developer

0개의 댓글