-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.js
More file actions
29 lines (25 loc) · 720 Bytes
/
loops.js
File metadata and controls
29 lines (25 loc) · 720 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
// Sample JS programs using loop implementations.
// while loop.
var i = 1;
while (i < 10) {
console.log("Iteration " + i);
i++;
}
// do-while loop.
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
var i = 0;
do {
console.log( days[i++] );
} while (i < days.length);
// for loop.
for (var x = 1; x <= 9; x++) {
for (var y = 1; y <= 9; y++) {
console.log(x + " X " + y + " = " + (x * y));
}
}
// for-in loop.
var months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
for (var idx in months) {
console.log("It's the month of " + months[idx] + "!");
}