Skip to content

Commit bded6b9

Browse files
committed
For loop 🔃
1 parent 6f51669 commit bded6b9

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed
+26-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// for loop
22
for (var i = 1; i <= 20; i += 2) {
3-
console.log(i);
3+
console.log(i);
44
}
55

66
// i = 0, 0 < 10 true, log i to console, i++
@@ -11,13 +11,34 @@ for (var i = 1; i <= 20; i += 2) {
1111

1212
var john = ['John', 'Smith', 1990, 'designer', false, 'blue'];
1313
for (var i = 0; i < john.length; i++) {
14-
console.log(john[i]);
14+
console.log(john[i]);
1515
}
1616

17+
// For In Loop (The JavaScript for/in statement loops through the properties of an object:)
18+
console.log('\nFor In Loop');
19+
20+
const object = { name: 'Lakshman', age: 22, eye: 'blue' };
21+
console.log('For In Loop');
22+
for (const x in object) {
23+
console.log(`${x}: ${object[x]}`);
24+
}
25+
26+
// The For/Of Loop (The for...of statement creates a loop iterating over iterable objects)
27+
console.log('\nFor of Loop');
28+
29+
for (const person of john) {
30+
console.log(person);
31+
}
32+
33+
// forEach()
34+
console.log('\nforEach');
35+
john.forEach(el => console.log(el));
1736

1837
// While loop
38+
console.log('\nWhile Loop');
39+
1940
var i = 0;
2041
while (i < john.length) {
21-
console.log(john[i]);
22-
i++;
23-
}
42+
console.log(john[i]);
43+
i++;
44+
}

0 commit comments

Comments
 (0)