How to use While Loop in C#

In this article, I will explain how while Loop can be used in C#.
  • 2512


While statement is a Iterative statements repeat a particular statement block until a condition has been reached. The statement block of while statement is executed while the Boolean expression is true. The statement block is not executed if the Boolean expression is initially false. The syntax for the while loop is as follows.


while (''condition'')


      // C# statements go here



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

class WhileTest


    static void Main()


        int r = 1;

        int s = 10;

        int sum = 0;

        while (r < 10)


             sum = r + s ;

            Console.WriteLine(" value of sum is {0}", sum);






The output of following program


© 2020 DotNetHeaven. All rights reserved.