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.


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:



Thanks.

0 comments


Leave a comment

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

Welcome to SQL Tutorials Point

Don't have an account? Click here to Create a new account, it takes less than a minute.