Skip to content

Commit 2b51f56

Browse files
committed
feat: add control structures explanation
1 parent 5869833 commit 2b51f56

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

basics/control-structures.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// 📌 JavaScript Basics - Control Structures
2+
3+
// Welcome to the fourth section of the JavaScript Basics tutorial!
4+
// Here, you'll learn about control structures used to manage the flow of a program.
5+
6+
// 🔄 Conditional Statements
7+
// if, else if, else
8+
let age = 18;
9+
if (age < 18) {
10+
console.log("You are a minor.");
11+
} else if (age === 18) {
12+
console.log("You just became an adult!");
13+
} else {
14+
console.log("You are an adult.");
15+
}
16+
17+
// 🔁 Looping Structures
18+
19+
// for loop - Executes a block of code a fixed number of times
20+
for (let i = 0; i < 5; i++) {
21+
console.log("Iteration:", i);
22+
}
23+
24+
// while loop - Executes while a condition is true
25+
let count = 0;
26+
while (count < 3) {
27+
console.log("While loop count:", count);
28+
count++;
29+
}
30+
31+
// do-while loop - Executes at least once, then repeats while condition is true
32+
let number = 0;
33+
do {
34+
console.log("Do-while count:", number);
35+
number++;
36+
} while (number < 3);
37+
38+
// 🎯 Switch Statement - A cleaner way to handle multiple conditions
39+
let day = "Monday";
40+
switch (day) {
41+
case "Monday":
42+
console.log("Start of the week!");
43+
break;
44+
case "Friday":
45+
console.log("Weekend is near!");
46+
break;
47+
default:
48+
console.log("It's a regular day.");
49+
}
50+
51+
// 💡 Practice using these control structures in different scenarios!

0 commit comments

Comments
 (0)