-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloops.js
107 lines (83 loc) · 1.99 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
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
// if loop
// entering a bus
//conditional loops
var ticket = true;
var seniorCitizen = true;
if (ticket) {
console.log("enter into the bus");
}
// if else loop
if (ticket) {
console.log("enter into the bus");
} else {
console.log("dont enter into the bus");
}
//if else if loop
if (ticket) {
console.log("enter into the bus");
} else if (seniorCitizen) {
console.log("enter into the bus");
} else {
console.log("dont enter into the bus");
}
// women kid handicapped
// switch case
var ticket = "womenasadasd";
switch (ticket) {
case "normalTicket":
case "seniorCitizen":
case "women":
case "kid":
case "handicap":
console.log("enter into the bus");
break;
default:
console.log("dont enter please you have to take a ticket");
}
// while loop
// bus bay or a terminal ---> capacity to maintain only 5 buses
// straight way
var terminalCapacity = 0;
var bus = 0;
while (terminalCapacity < 5) {
terminalCapacity++;
console.log(`park the bus : bus ${terminalCapacity} `);
}
if (terminalCapacity === 5) {
console.log("Terminal capacity is filled, Please check for next terminal");
}
// // reverse order
var terminalCapacity = 5;
var bus = 0;
while (terminalCapacity < 5) {
console.log(`park the bus : bus ${terminalCapacity} `);
terminalCapacity--;
}
if (terminalCapacity === 0) {
console.log("Terminal capacity is filled, Please check for next terminal");
}
// for loop
//assigning and declaring
// condition check
// incrment and decrement logic
var tc;
for (tc = 1; tc <= 5; tc++) {
console.log(`park the bus : ${tc}`);
// //1 st iteration
// // tc= 1
// // tc<5 ==> enter into the loop
// // print out "park the bus : 1"
// // tc=2
// // tc< 5 ==> enter the loop
// // print out "park the bus : 2"
}
var tc;
var busnumber = 0;
for (tc = 5; tc >= 1; tc--) {
busnumber++;
console.log(`park the bus : ${busnumber}`);
}
for (i = 0; i < 5; i++) {
console.log(`park the bus : bus ${terminalCapacity} `);
}
// foreach defining arrays