CSharp examples for Language Basics:for
Counter-controlled repetition with the while iteration statement.
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(); } }