const arr = ['a', 'b', 'c', 'd'];
const obj = {
color = 'red',
width = 200,
height = 200,
}
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
for (const item of arr) {
console.log(item);
}
for (const index in arr) {
console.log(arr[index]);
}
for (const key in obj) {
console.log(key);
}
let i = 0;
while (i < arr.length)
console.log(arr[i++]);
i = 0;
do {
console.log(arr[i++]);
} while (i < arr.length)
while 문과 do while 문의 차이점은 비교하는 시점이 서로 다른 부분이다.
while 문의 경우 비교하는 시점이 while 안에서 부터 시작된다면 do while의 경우 먼저 명령어를 실행하고 나서
그 다음 아래 명령어를 실행할지 실행하지 말지에 대한 판단을 하게 된다.