File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 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!
You can’t perform that action at this time.
0 commit comments