Introduction:

In this article we will learn what is while loop in c# or how to use while loop in c# with example

Description:

The while statement frequently executes a block of statements until a specified expression evaluates to false. The expression is evaluated each time the loop is encountered and the evaluation result is true, the loop body statements are executed.

The  while loop is one of the important looping concept, that is being widely used in C sharp programming language. To understand the concept of while loop, consider the following diagram.

While Loop in c#

Example :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int number, total, i;
 
            Console.WriteLine("Enter a Number");
            number = Convert.ToInt32(Console.ReadLine());
 
            i = 1; //Initialization
            //Check  condition true or false
            while (i <= 10)
            {
                total = number * i;
                Console.WriteLine("{0} x {1} = {2}", number, i, total);
                i++; //Increment by one
            }
            Console.ReadLine();
 
        }
 
    }
}

 

 

Output:

While Loop in c#


0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like