자바스크립트
home
2025 자바스크립트 초급 1500제
home

E0204_개념02_연속누적2for문

개념

<script> /* [연속 누적2 for문] 반복문을 사용해서 보기와 같이 출력하시오. [보기] 0 0 2 2 4 6 6 12 8 20 */ let total = 0; let a = 0; for(let i = 0; i < 5; i++) { total += a; document.write(a, " ", total, "<br>"); a += 2; } document.write("<br>"); let total2 = 0; for(let i = 0; i < 10; i += 2) { total2 += i; document.write(i, " ", total2, "<br>"); } </script>
HTML
복사

영상