-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23_iterations.js
More file actions
83 lines (61 loc) · 1.64 KB
/
23_iterations.js
File metadata and controls
83 lines (61 loc) · 1.64 KB
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
// for loop
for (let i = 0; i <= 10; i++) {
const element = i;
if (element == 5) {
console.log("5 is best number");
}
console.log(element);
}
// console.log(element); error --> element is not defined
for (let i = 0; i <= 10; i++) {
console.log(`Outer loop value: ${i}`);
for (let j = 0; j <= 10; j++) {
console.log(`Inner loop value: ${j} and inner value ${i}`);
}
}
for (let i = 1; i <= 10 ; i++) {
console.log(`Table: ${i}`);
for (let j = 1; j <= 10; j++) {
console.log(i + '*' + j + ' = ' + i*j);
// console.log(`${i}*${j} = ${i*j}`);
}
}
let myArray = ["Jethalal", "Babitaji", "Iyer"]
console.log(myArray.length);
for (let index = 0; index < myArray.length; index++) {
const element = myArray[index];
console.log(element);
}
// <= --> undefined
// break and continue
for (let index = 1; index <= 20; index++) {
if (index == 5) {
console.log(`Detected 5`);
break
}
console.log(`Value of index is ${index}`);
}
for (let index = 1; index <= 20; index++) {
if (index == 5) {
console.log(`Detected 5`);
continue
}
console.log(`Value of index is ${index}`);
}
// while and do-while loop
let index = 0
while (index <= 10) {
console.log(`Value of index is ${index}`);
index = index + 2
}
let myArrayOne = ['Tarak', "Bhide", "Popat"]
let arr = 0
while (arr < myArrayOne.length) {
console.log(`Member is ${myArray[arr]}`);
arr = arr + 1
}
let score = 11
do {
console.log(`Score is ${score}`);
score++
} while (score <= 10);