while 루프의 목적은 표현식이 참인 한 명령문이나 코드 블록을 반복적으로 실행하는 것입니다. 표현식이 거짓이 되면 루프가 종료됩니다.
예
다음 코드를 실행하여 중첩된 while 루프를 사용하는 방법을 배울 수 있습니다.
라이브 데모
<html>
<body>
<script>
var height = 2;
var width = 8;
var col = 0;
var row = 0;
document.write("Starting Loop<br> ");
while (row < height) {
col = 0;
while(col < width) {
document.write("#");
col++;
}
document.write("<br>");
row++;
}
document.write("Loop stopped!");
</script>
</body>
</html>