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

E0204_개념01_연속누적while문

개념

<script> /* [연속 누적 while문] - 연속 누적은 반복문에서 매번 계산된 값을 - 계속 더해가면서 합계를 구하는 방식입니다. - 반복문을 사용해서 보기와 같이 출력하시오. [보기] 0 0 1 1 2 3 3 6 4 10 5 15 6 21 7 28 8 36 9 45 */ let total = 0; let a = 0; let i = 0; while(i < 10) { total += a; a += 1; document.write(i, " ", total, "<br>"); i += 1; } document.write("<br>"); let total2 = 0; let i2 = 0; while(i2 < 10) { total2 += i2; document.write(i2, " ", total2, "<br>"); i2 += 1; } </script>
HTML
복사

영상