-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathloops.js
More file actions
39 lines (31 loc) · 679 Bytes
/
Copy pathloops.js
File metadata and controls
39 lines (31 loc) · 679 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
var names = ['John', 'Jane', 'Mary', 'Mark', 'Bob'];
// for loops
//example one
for (var i = 0; i < names.length; i++) {
console.log(names[i]);
}
//example two
for (var i = names.length - 1; i >= 0; i--) {
console.log(names[i]);
}
// while loops
var i = 0;
while(i < names.length) {
console.log(names[i]);
i++;
}
// break and continue
//example one
for (var i = 1; i <= 7; i++) {
console.log(i);
if (i === 3) {
break;
}
}
//example two
for (var i = 1; i <= 7; i++) {
if (i === 3) {
continue;
}
console.log(i);
}