-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoops.js
81 lines (64 loc) · 1.67 KB
/
Loops.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
// A loop is defined as the set of instuction can repeated multiple times
// In js there are three main types of loops
// 1. for loop
// 2. while loop
// 3. do while loop
// Another its not a type
// for each loop
// 1. for loop
// for (let i = 0; i <= 16; i += 2) {
// if(i%2===0)
// console.log("*", i);
// statement
// }
// 2. while loop
// In while loop we defined outside the variable
// let j = 12;
// while (j < 15) {
// if(j===13){
// console.log("**", j);
// break;
// }
// j++}
// Break Statement Terminate the loop / move outside the loop
// continue statement is used to skip the current iteration wihin the loop and proceed to the next iteration of
// let k=0;
// do{
// if(k===2)
// {
// k++;
// continue;
// }
// console.log(k);
// k++;
// }while(k<=15);
// for (let i = 1; i <= 10; i++) {
// if (i % 2 === 0) {
// continue;
// }
// console.log(i);
// }
// 3. do while loop
// do run atleast one time if the statement is wrong also run
// let i = 19;
// do {
// console.log("This is the do while loop");
// i++;
// } while (i <= 23);
// ForEach Loop in JS : the basic function of foreach loop specified operation for each element
// let numbers = [1, 4, 2, 7, 56, 7, 8, 32];
// numbers.forEach(function (element) {
// console.log(element);
// });
// let cars=['civic' , 'city' , 'V8']
// cars.forEach(function (elements,index,arrays){
// console.log(elements);
// console.log(index);
// console.log(arrays);
// });
// without foreach loop the method is difficult are as follows :
// Discuss
// let password;
// do {
// password = prompt('Enter the passcode, please');
// } while (password !== 'web');