CSharp.Net-Informations.com

  How to use C# while loop




   Categories

    HOME
    VB.NET
    CSHARP


   














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

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
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved