-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor.html
More file actions
63 lines (52 loc) · 1.35 KB
/
for.html
File metadata and controls
63 lines (52 loc) · 1.35 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>For looping statement</title>
</head>
<body></body>
<script>
// for( ; ) start; declare a variable & gives him value.....is called
// Initialize
// for ( ; ;) end; condition...how it is stop.
// for ( ; ; ) step; how many times it perform
for (let start = 1; start <= 10; start++) {
console.log("Welcome to Akand NextGen Stack", start);
}
// Even
for (let n = 10; n >= 1; n -= 2) {
console.log(n);
}
// Odd
for (let n = 1; n <= 10; n = n + 2) {
console.log(n);
}
// break keyword
for (let n = 10; n >= 1; n--) {
if (n == 6) {
break;
}
console.log(n); // 10, 9, 8, 7..not 6 bcz break call before console.log
}
for (let n = 10; n >= 1; n--) {
console.log(n); // 10, 9, 8, 7, 6....bcz break call after console.log
if (n == 6) {
break;
}
}
// Continue
for (let n = 0; n <= 20; n += 2) {
if (n % 3 == 0) {
continue;
}
console.log(n); // missing or skip 6, 12, 18
}
for (let n = 1; n <= 20; n++) {
if (n % 5 == 0) {
continue;
}
console.log(n); // missing or skip 5, 10, 15, 20
}
</script>
</html>