-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (52 loc) · 1.17 KB
/
script.js
File metadata and controls
57 lines (52 loc) · 1.17 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
// // while Loops
// /*
// Each execution of code is known as itration.
// If we don't know the total number of itration.We use the while Loop.
// */
let i = 0;
while (i <= 10) {
console.log(`Itration: ${i++}`);
}
/*
ForLoop is the advance version of while loop
for(reference;condition;iteration){
}
*/
for (let x = 0; x <= 10; x++) {
console.log(`Iteration: ${x}`);
}
i = 0;
for (; i <= 10; i++) {
console.log(`Itration: ${i}`);
}
for (; i <= 10; ) {
console.log(`Itration: ${i++}`);
}
// The below code is infinte Loop
// for(;;){
// console.log("Infinite Loop");
// }
//Break and continue
for (let x = 0; x <= 10; x++) {
if (x % 2 == 1) continue;
console.log(`${x}`);
}
//The continue keyword skip current itration if on the basis of any condition.
for (let x = 0; x <= 5; x++) {
for (let y = 0; y <= 5; y++) {
if (y == 2) {
break;
}
console.log(`x:${x} y:${y}`);
}
}
// The break keyword stop all the itration of the loop.
// In nested loop inorder to stop the parent loop we need to label the parent loop
main: for (let x = 0; x <= 5; x++) {
for (let y = 0; y <= 5; y++) {
if (y == 2) {
break main;
}
console.log(`x:${x} y:${y}`);
}
}