-
for문과 while문의 차이점Study/JavaScript 2020. 5. 1. 21:25
while문과 do-while문의 차이점은 조건을 먼저 검사하느냐 나중에 검사하느냐일 뿐 동작 방식은 동일합니다.
반복횟수를 알고 있을 때 주로 사용한다.
for문이 정해진 횟수만큼 반복한다면, while 문은 조건식이 true 일 경우에 계속해서 반복합니다
So you may be wondering when to use a while loop! The syntax of a for loop is ideal when we know how many times the loop should run, but we don’t always know this in advance. Think of eating like a while loop: when you start taking bites, you don’t know the exact number you’ll need to become full. Rather you’ll eat while you’re hungry. In situations when we want a loop to execute an undetermined number of times, while loops are the best choice.
'Study > JavaScript' 카테고리의 다른 글
Higher order function (0) 2020.05.02 What are other uses of functions as data? (0) 2020.05.02 what is Scope? (0) 2020.04.30 What are the advantages of function expressions? 함수표현식 vs 함수 선언식 (0) 2020.04.30 Why do I need to use `return`? (0) 2020.04.30