-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrayLoop.js
107 lines (86 loc) · 1.72 KB
/
arrayLoop.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
// Display every element of an array, using the 'for' loop.
var numbers = [45, 87, 89, 56, 32, 51, 25];
for (var i = 0; i < 7; i++) {
// console.log(i);
var number = numbers[i];
console.log(number);
}
*/
/*
// The above same task (displaying every elements of an array), using the 'while' loop.
var numbers = [45, 87, 89, 56, 32, 51, 25];
var indexNumber = 0;
while (indexNumber < 7) {
var number = numbers[indexNumber];
console.log(number);
indexNumber++;
}
*/
/*
// Output ||
45
87
89
56
32
51
25
*/
/*
// Display every element of an array, using the 'for' loop [using the condition of unlimited array-length].
var numbers = [45, 87, 89, 56, 32, 51, 25, 188, 41];
for (var i = 0; i < numbers.length; i++) {
// console.log(i);
var number = numbers[i];
console.log(number);
}
*/
/*
// The above same task using the 'while' loop.
var numbers = [45, 87, 89, 56, 32, 51, 25, 188, 41];
var indexNumber = 0;
while (indexNumber < numbers.length) {
var number = numbers[indexNumber];
console.log(number);
indexNumber++;
}
*/
/*
// Output ||
45
87
89
56
32
51
25
188
41
*/
/*
// Display every element of an array, using the 'for' loop [using the condition of unlimited array-length and string-elements of the array]
var items = ["bottle", "mouse", "sunglass", "pen", "notebook"];
for (var i = 0; i < items.length; i++) {
var item = items[i];
console.log(item);
}
*/
/*
// The above same task using the 'while' loop.
var items = ["bottle", "mouse", "sunglass", "pen", "notebook"];
var indexNumber = 0;
while (indexNumber < items.length) {
var item = items[indexNumber];
console.log(item);
indexNumber++
}
*/
/*
// Output ||
bottle
mouse
sunglass
pen
notebook
*/