///////////////////////////////////////
// The while Loop
for (let rep = 1; rep <= 10; rep++) {
console.log(`Lifting weights repetition ${rep} 🏋️♀️`);
}
let rep = 1;
while (rep <= 10) {
// console.log(`WHILE: Lifting weights repetition ${rep} 🏋️♀️`);
rep++;
}
let dice = Math.trunc(Math.random() * 6) + 1;
while (dice !== 6) {
console.log(`You rolled a ${dice}`);
dice = Math.trunc(Math.random() * 6) + 1;
if (dice === 6) console.log('Loop is about to end...');
}
*/
for 정확히 몇번 실행될것을 정하지 않고 한 컨디션아래 코드실행 시킬때 while을 쓰는 것이 좋다
'공부자료 > 자바스크립트' 카테고리의 다른 글
ddays 계산하기 (0) | 2021.09.29 |
---|---|
Coding Challenge - sum by looping (0) | 2021.09.20 |
섹션 2 Javascript Fundamentals part 2 - Looping Backwards and Loops in Loops (0) | 2021.09.20 |
섹션 2 Javascript Fundamentals part 2 - Looping Arrays, Breaking and Continuing (0) | 2021.09.20 |
섹션 2 Javascript Fundamentals part 2 - Iteration: The for Loop (0) | 2021.09.20 |