forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.js
More file actions
36 lines (31 loc) · 823 Bytes
/
loop.js
File metadata and controls
36 lines (31 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const carsInReverse = ['Ford', 'Honda', 'BMW', 'Lexus'];
for (let index = carsInReverse.length - 1; index > -1; index--) {
console.log(carsInReverse[index]);
}
const person = {
firstName: "Jane",
lastName: "Doe",
birthDate: "Jan 5, 1925",
gender: "female"
}
for (const key in person) {
console.log(person[key]);
}
for (const key in person) {
if (key === "birthDate") {
console.log(person.birthDate);
}
}
let number = 0;
while (number < 1000) {
number++;
console.log(number);
}
let number = 0;
do {
number++;
console.log(number);
} while (number < 1000);
/* A for loop is better than a while loop when you know the number of iterations.
A for...in loop is used with objects only.
A do while loop always runs once before testing the conditional. The while loop tests the conditional first. */