- Get link
- X
- Other Apps
Control Structures in C# 🚀 Control structures help control the flow of execution in a program. C# provides conditional statements ( if-else , switch ) and loops ( for , while , do-while ) to handle different scenarios. 1️⃣ Conditional Statements 🔹 if-else Statement The if-else statement executes code based on conditions . Syntax: if (condition) { // Code runs if condition is true } else if (anotherCondition) { // Code runs if anotherCondition is true } else { // Code runs if none of the above conditions are true } Example: int age = 20; if (age >= 18) { Console.WriteLine("You are an adult."); } else { Console.WriteLine("You are a minor."); } ✅ Nested if-else int number = 10; if (number > 0) { if (number % 2 == 0) { Console.WriteLine("Positive Even Number"); } else { Console.WriteLine("Positive Odd Number"); } } 🔹 switch Statement The switch statemen...