개념
<script>
/*
[반복문 옵션 continue]
- 숫자 1부터 9 사이의 랜덤 숫자 2개를 저장합니다.
- 두 숫자의 합이 10이 될 때까지 반복문을 사용하여 프로그램을 구현하시오.
*/
/*
[출력예시]
1 1
5 2
2 7
5 3
5 5
10
3 8
3 9
2 5
8 4
1 2
7 3
10
*/
// continue 사용 전
while(true) {
let r = Math.floor(Math.random() * 9) + 1;
let r2 = Math.floor(Math.random() * 9) + 1;
let total = r + r2;
document.write(r, " ", r2, "<br>");
if(total == 10) {
document.write(total);
break;
}
}
document.write("<br><br>");
// continue 사용 후
while(true) {
let r = Math.floor(Math.random() * 9) + 1;
let r2 = Math.floor(Math.random() * 9) + 1;
let total = r + r2;
document.write(r, " ", r2, "<br>");
if(total != 10) {
continue;
}
document.write(total);
break;
}
</script>
HTML
복사


