Learn C# Programming
Master C# programming from basics to advanced concepts with our comprehensive tutorial series. Perfect for beginners and experienced developers.
C# do...while Loop
The do...while loop executes a block of code at least once, then repeats as long as a specified condition is true.
Basic do...while Syntax
do
{
// Code to execute
// This runs at least once
} while (condition);
Key Difference: while vs do...while
// while loop - may not execute at all
int x = 10;
while (x < 5)
{
Console.WriteLine("This will never print");
x++;
}
// do...while loop - executes at least once
int y = 10;
do
{
Console.WriteLine("This will print once: " + y);
y++;
} while (y < 5);
// Output: "This will print once: 10"
Menu System Example
int choice;
do
{
Console.WriteLine("\n=== MENU ===");
Console.WriteLine("1. Option 1");
Console.WriteLine("2. Option 2");
Console.WriteLine("3. Option 3");
Console.WriteLine("0. Exit");
Console.Write("Enter your choice: ");
if (int.TryParse(Console.ReadLine(), out choice))
{
switch (choice)
{
case 1:
Console.WriteLine("You selected Option 1");
break;
case 2:
Console.WriteLine("You selected Option 2");
break;
case 3:
Console.WriteLine("You selected Option 3");
break;
case 0:
Console.WriteLine("Goodbye!");
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
else
{
Console.WriteLine("Invalid input. Please enter a number.");
choice = -1; // Force loop to continue
}
} while (choice != 0);
// Output: "This will print once: 10"
Frequently Asked Questions
Master C# Programming with Our Comprehensive Tutorial
Our C# programming tutorial is designed to take you from a complete beginner to an advanced developer. Whether you're looking to build web applications, desktop software, or mobile apps, C# provides the foundation you need for modern software development.
Start with the basics like variables, data types, and control structures, then progress to advanced topics including object-oriented programming, LINQ, async programming, and more. Each lesson includes practical examples and exercises to reinforce your learning.
Join thousands of developers who have learned C# programming through our step-by-step tutorials. Begin your journey today and unlock the power of .NET development.