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  ww. j a v a  2s .  c o  m
{
   public static void Main(string[] args)
   {

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

   }
}

Result

Quiz

Exercise