-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5. loops.js
39 lines (28 loc) · 932 Bytes
/
5. loops.js
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
// for - loops through a block of code a number of times
for(let i=0; i<5; i++){}
// -------------
// for/in or index loop - loops through the properties of an object
person = {name:"John", age:25};
for (let x in person){
person[x]
}
// Do not use for in over an Array if the index order is important.
numbers = [1, 2, 3, 4, 5]
for (let x in numbers){
numbers[x]
}
// ----------------
// for/of - loops through the values of an iterable object
for (let n of numbers){}
// ----------------
/* Array.forEach() - calls a function once for each array element
that the function takes 3 arguments: value, index, array itself. */
numbers.forEach((value, index, array)=>{})
// ----------------
// while - loops through a block of code while a specified condition is true
while(true){break}
// ----------------
// do/while - also loops through a block of code while a specified condition is true
do{
break
}while(true)