-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloops.js
53 lines (36 loc) · 760 Bytes
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
// for
var arr=[20,30,4];
for(var index=0;index<arr.length;index++){
//iteration logic
var m1=arr[index]*2;
console.log(m1);
}
/// for each
for(e of arr){
console.log(e);
}
// does the job as the above for each statement
for(e in arr){
console.log(arr[e]);
}
// objects
var obj={name:'ali',age:20,address:'Cairo'};
for(attr in obj){
//printing attributes of the object
console.log(attr);
//printing the values
console.log(obj[attr]);
console.log(obj.attr);
}
// we can not use for of with objects ; literals, constructor functions...
// while
var num=100;
while(num>=100){
console.log(num);
num--;
}
// executes at least once .. or more
do{
console.log(num);
num++;
} while(num>100);