[JavaScript] 반복문의 효용성

겨레·2025년 5월 25일

coding everybody를 10번 반복해서 출력하고 싶을 때, 일반적으로 아래와 같이 작성함.

document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');
document.write('coding everybody');

만약 큰 규모의 데이터를 다뤄야 한다면?

var i = 0;
while(i < 10){
    document.write('coding everybody <br />');
    i++;
}
profile
호떡 신문지에서 개발자로 환생

0개의 댓글