CSharp - Statement while loops

Introduction

while loops repeatedly execute a body of code while a bool expression is true.

The expression is tested before the body of the loop is executed.

For example:

int i = 0;
while (i < 3)
{
       Console.WriteLine (i);
       i++;
}

Demo

using System;
class MainClass//from  w w w. j a va 2  s .co  m
{
   public static void Main(string[] args)
   {

         int i = 0;
         while (i < 3)
         {
           Console.WriteLine (i);
           i++;
         }

   }
}

Result

Quiz

Exercise