-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.js
More file actions
43 lines (30 loc) · 719 Bytes
/
loops.js
File metadata and controls
43 lines (30 loc) · 719 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
37
38
39
40
41
// for loops
for (let i = 0; i < 5; i++) // don't use var to declare variable as it has global scope
{
console.log(i)
}
let person = ["ram", "shyam", "geeta"]
for (let i = 0; i < person.length; i++) {
console.log(person[i]);
}
// while loops
let i = 0;
while (i < 5) { // declare and assign the variable first
console.log(i)
i++;
}
let j = 0;
do {
console.log(j)
j++;
} while (j < 5)
// difference between let and var
var x; // global variable
let q; // limited block scope
// break(exit the loop)
// continue(to skip the iteration)
// ourArray.forEach((current, index) => {
// console.log(current)
// ourArray.splice(index, 1, current + 1);
// });
// console.log(ourArray)