Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 04week/loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
let whileCounter = 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to answer the questions about how for loop is different than a while loop,
how for loop is different that for in loop, and how a while loop is different than a do while loop

let doWhileCounter = 1;
let carsInReverse = ['Hyundai','Mercedes','Toyota','Honda'];
let persons = {
firstName: "Jane",
lastName: "Doe",
birthDate: "Jan 5, 1925",
gender: "female"
}

for (let i=0; i<carsInReverse.length;i++){
console.log(carsInReverse[i]);
}

//let personsKeys = Object.keys(persons);
for (let j in persons) {
console.log(j);
}

for (let k in persons) {
if (k==='birthDate'){
console.log(persons[k]);
break;
}
}

while (whileCounter<5){
console.log(whileCounter);
whileCounter++;
}

do {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your do while loop prints 1 to 4.

console.log(doWhileCounter);
doWhileCounter++;
} while (doWhileCounter < 5);