while Loop in C# Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Looping in a programming language is a way to execute a statement or a set of statements multiple number of times depending on the result of the condition to be evaluated. while loop is an Entry Controlled Loop in C#. The test condition is given in the beginning of the loop and all statements are executed till the given boolean condition satisfies, when the condition becomes false, the control will be out from the while loop. Syntax: while (boolean condition) { loop statements... } Flowchart: Example 1: csharp // C# program to illustrate while loop using System; class whileLoopDemo { public static void Main() { int x = 1; // Exit when x becomes greater than 4 while (x <= 4) { Console.WriteLine("GeeksforGeeks"); // Increment the value of x for // next iteration x++; } } } Output: GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks Example 2: csharp // C# program to illustrate while loop using System; class whileLoopDemo { public static void Main() { int x = 10; // Exit when x becomes less than 5 while (x > 4) { Console.WriteLine("Value " + x); // Decrement the value of x for // next iteration x--; } } } Output: Value 10 Value 9 Value 8 Value 7 Value 6 Value 5 Comment More infoAdvertise with us Next Article C#- Nested loops A anshul_aggarwal Follow Improve Article Tags : C# CSharp-Basics Similar Reads C# Loops Looping in a programming language is a way to execute a statement or a set of statements multiple times, depending on the result of the condition to be evaluated to execute statements. The result condition should be true to execute statements within loops.Types of Loops in C#Loops are mainly divided 4 min read C#- Nested loops Nested loops are those loops that are present inside another loop. In C#, nesting of for, while, and do-while loops are allowed and you can also put any nested loop inside any other type of loop like in a for loop you are allowed to put nested if loop. for Loop: The functionality of for loop is quit 3 min read ref in C# The ref keyword in C# is used for passing or returning references of values to or from Methods. Basically, it means that any change made to a value that is passed by reference will reflect this change since you are modifying the value at the address and not just the value. It can be implemented in t 4 min read Partial Methods in C# C# contains a special method is known as a partial method, which contains declaration part in one partial class and definition part in another partial class or may contain both declaration and definition in the same partial class. Basically, partial methods exist in the partial class, or in the stru 2 min read C# Hello World The Hello World Program is the most basic program when we dive into a new programming language. This simply prints "Hello World!" on the console. In C#, a basic program consists of the following:A Namespace DeclarationClass Declaration & DefinitionClass Members(like variables, methods, etc.)Main 4 min read C# Main Thread In C#, threads are the smallest units of execution that allow parallel execution of code, enabling multiple tasks to run concurrently within a single process. The Thread class in the System.Threading namespace is used to create and manage threads. In C#, the Main method is the entry point of any con 5 min read Like