In this tutorial, while loop in C#. We have already discussed for loop in our previous tutorial. The while loop is another statement in C#.

After completing this tutorial you will be able to understand:

  • while loop in C#.
  • how to use while loop in c#.


While Loop is used to execute a block of code as long as the specified condition is true

The syntax for declaring While Loop:

In the above syntax, the statement may be a single line statement or block of statement. The statement executed until the condition is true.

while loop

The interesting fact about while loop that the stamen might not ever run. When the condition is tested.

An example of the while loop in C#.

Open visual studio and create a Console Application project in C# called WhileLoopDemo.

whole loop

Open Program.cs file and write the following code.

Run the program and look over the output window.

while loop


Hope you understand this small but very important tutorial about while loop in C#. I would like to have your feedback, comments and suggestions.

View More:

Thank You.