본문 바로가기

교육

자바스크립트 While 예제 알아보기

반응형



<!DOCTYPEhtml>

<html>

<head>

<metacharset="UTF-8">

<title>Insert title here</title>

</head>

<body>

*반복문 while *<br>

<scripttype="text/javascript">

vara= 1;

while(a <=5) {

     document.write('반복');

     a++;

}

document.write('<br>');

varb = 10;

do{

     document.write('최소 1회 수행');

     b++;

}while(b <= 5);

//------------------

document.write('<br>');

k = 1;

m = 0;

while(k){// true 하고 적은 것과 같은 결과 : 무한 루프

     //if(m === 5)continue;

     if(m === 10)break;

     document.write(k," ", m);// " "는 스페이스 효과

     m++;

     }

</script>

</body>

</html>



< 결과값 >


*반복문 while * 

반복반복반복반복반복

최소 1회 수행

1 01 11 21 31 41 51 61 71 81 9