Skip to content

Commit 273b203

Browse files
committed
add for_in_loop.html and for_of_loop.html for demonstrating JavaScript loops
1 parent 489ba2c commit 273b203

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
const person = {
11+
first_name : "sumit",
12+
last_name : "yadav",
13+
age : 25
14+
};
15+
16+
//document.write("the name is : ",person.first_name)
17+
18+
//console.log("the name is : ",person.first_name)
19+
20+
21+
// using loop for print all data
22+
for(key in person){
23+
document.write(key," = ",person[key],"<hr>")
24+
}
25+
26+
27+
// using array
28+
data = [12,13,14,15,16,17]
29+
for(i in data){
30+
document.write("<hr> ",i," = ",data[i])
31+
}
32+
33+
</script>
34+
35+
</head>
36+
<body>
37+
38+
</body>
39+
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
<script>
8+
9+
color = ["white","blue","green","yellow","pink"]
10+
11+
for(c of color){
12+
document.write("<hr>",c)
13+
}
14+
15+
// string
16+
17+
document.write("<br> ------------------------- ")
18+
19+
function print(){
20+
Data = "bhoomi"
21+
for(i of Data){
22+
//document.write("<br>",i)
23+
document.getElementById("print_data").innerHTML += "<br>"+i
24+
25+
}
26+
}
27+
28+
</script>
29+
30+
</head>
31+
<body>
32+
33+
<h1>Welcome to codeswithpankaj.com</h1>
34+
<button onclick="print()">Print</button>
35+
<p id="print_data"></p>
36+
37+
38+
</body>
39+
</html>

0 commit comments

Comments
 (0)