CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to use C# while loop

The C# while statement continually executes a block of statements until a specified expression evaluates to false .

while (expression) statement

Like if statement the while statement evaluates the expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false.

  int count = 1;
  while (count < = 4)
  {
	  MessageBox.Show("The value of i is : " + count);
	  count = count + 1;

}

The C# while statement executes a statement or a block of statements until a specified expression evaluates to false . The above program the loop will execute the code block 4 times.

You can implement an infinite loop using the while statement as follows:

  while (true){
	  // statements

}

         C# Source Code Download           Print Source Code
         How to use C# while loop - Download
        
C# Tutorial

using System;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int count = 1;
            while (count < = 4)
            {
                MessageBox.Show("The value of i is : " + count);
                count = count + 1;
            }
        }
    }
}



CSharp Statements Related Contents
*     How to use C# if else statements
*     How to use C# for loop
*     How to use C# foreach loop
*     How to use C# do while loop
*     How to use C# switch case statements
*     How to use C# exceptions statements


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.