-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8-loops.html
127 lines (87 loc) · 2.49 KB
/
8-loops.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>loops in javaScript</title>
</head>
<body>
<script>
// for loop
// let name=["ali","hassan","abbas","Muhammad"];
// console.log("the student names are...")
// for (let index = 0; index < name.length; index++) {
// let element = name[index];
// console.log( element)
// }
// forEach loops
// name.forEach(element => {
// console.log(element);
// // use document.write for print javaScript in page
// document.write(element +"<br>" );
// });
// // for of loop
// console.log("using for of looop in javaScript")
// for (element of name){
// console.log(element);
// }
// for in loop
// for in loop is used for iterate over object in javaScript
// let student={
// Name: "Saleem Raza",
// class: "4-B",
// id: "CSC-20F-151",
// Univerasity: "SMI University"
// }
// for (const key in student) {
// console.log("the "+ ""+key+" of "+ "student is: " + ""+ student[key]);
// }
//for loops
// example:1
//get the output of sum of n number using for loop
// let sum=0;
// let n=prompt("enter the n number");
// n=Number.parseInt(n);
// for(let i=0; i<n; i++){
// sum+=(i+1); //sum=sum+(i+1) //same both are
// }
// console.log(sum);
// example:2
// get the output of sum of n number of factorial
// let factorial=1;
// let a=1;
// for (let i =prompt("enter the value"); i > a; i--) {
// factorial*=i;
// }
// console.log(factorial);
// for in loops:
// for in loops mostly use in object and arrays
//example:1
let obj={
ali:5,
hassan:5,
hussain:10,
sajjad:20
}
for (const key in obj) {
console.log("the marks of "+ key +" is " + obj[key]);
}
// for of loop
// example:01
let a="ali raza"
for(let key of a){
console.log(a);
}
//while loop in javaScript
//example:1
let i=0;
let b=prompt("enter the value");
b=Number.parseInt(b);
while (i<b) {
console.log(b);
b++;
}
</script>
</body>
</html>