예제
<script>
/*
[문제]
반복문을 사용해서 보기와 같이 출력하시오.
[보기]
0 1
1 2
2 3
3 1
4 2
5 3
6 1
7 2
8 3
9 1
*/
</script>
HTML
복사
정답
<script>
/*
[문제]
반복문을 사용해서 보기와 같이 출력하시오.
[보기]
0 1
1 2
2 3
3 1
4 2
5 3
6 1
7 2
8 3
9 1
*/
// [for문]
let count = 1;
for(let i = 0; i < 10; i++) {
document.write(i, " ", count, "<br>");
count += 1;
if(count == 4) {
count = 1;
}
}
document.write("<br>");
// [while문]
let count2 = 1;
let i = 0;
while(i < 10) {
document.write(i, " ", count2, "<br>");
count2 += 1;
if(count2 == 4) {
count2 = 1;
}
i += 1;
}
</script>
HTML
복사


