Counter-controlled repetition with the while iteration statement. - CSharp Language Basics

CSharp examples for Language Basics:for

Description

Counter-controlled repetition with the while iteration statement.

Demo Code

using System;/* w w w.  j  a  va2  s . c  o  m*/
class WhileCounter
{
   static void Main()
   {
      int counter = 1; // declare and initialize control variable
      while (counter <= 10) // loop-continuation condition
      {
         Console.Write($"{counter}  ");
         ++counter; // increment control variable
      }
      Console.WriteLine();
   }
}

Result


Related Tutorials