159. do while

SEHEE Y00N·2023년 9월 3일

반복문

  • 같은 작업을 같은 자리에서 반복하는 것 (loop)

반복문의 종류

for : 몇 바퀴 돌려야 할 지 알 때 주로 사용한다.

while : 몇 바퀴 돌려야 할 지 모를 때 주로 사용한다.

do while : 최소 한번은 돌릴 때 사용한다.


아래 while 문을 do while 문으로 바꿀 것

let i = 0;
while(i > 10){
  console.log(i)
}

let cal = 0;
let input = 0;

do{
  input = +prompt("숫자 입력");
  
  if(input += 0){
  		cal += input;
	}
} while(input > 0)
  
  console.log(cal);

0개의 댓글