Admin Name
Dashboard
Categorey
Sub Categorey
Artilces
Users
Settings
Logout
Welcome to the Admin Panel
Create Post
Select Categorey
- Select -
coding
Select Sub Categorey
Title Name :
Defination :
Control statements in C# are used to determine the flow of execution based on conditions and loops. These include decision-making (if, else, switch) and looping (for, while, do-while, foreach) constructs.
Code :
using System; class Program { static void Main() { int number = 10; // if-else example if (number > 0) { Console.WriteLine("Positive Number"); } else { Console.WriteLine("Non-Positive Number"); } // switch example switch (number) { case 10: Console.WriteLine("Number is 10"); break; default: Console.WriteLine("Unknown number"); break; } // for loop example for (int i = 1; i <= 5; i++) { Console.WriteLine("Count: " + i); } } }
Code Part 2 :
string[] colors = { "Red", "Green", "Blue" }; foreach (string color in colors) { Console.WriteLine(color); }
Upload Image 1
Upload Image 2
Summary
Control statements are crucial for creating logic in applications. if-else and switch are used for decision-making, while loops (for, while, do-while, foreach) help execute code repeatedly based on a condition.
YouTube Link
Seo Title
Meta Keywords
Meta Description
Introduction to C#
Edit
Variables and Data Types in C#
Edit
Operators in C#
Edit
Control Statements in C# – if, else, switch, and loops Explained
Edit
Loops in C# – for, while, do while, and foreach
Edit
Jump Statements in C# – break, continue, return Explained with Examples
Edit
Conditional Statements in C# if, else if, else, switch Explained with Examples
Edit
Loops in C# – For, While, and Do While with Examples
Edit
Hrjejd
Edit