5.1.The while Loop

A while loop will check a condition and then continues to execute a block of code as long as the condition evaluates to a boolean value of true.

Its syntax is as follows: while () { }. The statements can be any valid C# statements. The boolean expression is evaluated before any code in the following block has executed. When the boolean expression evaluates to true, the statements will execute and recheck the boolean expression again and again until the boolean expression false, the statements will stopped.
The While Loop: WhileLoop.cs

using System;
class WhileLoop
   public static void Main()
        int index = 1;

        while (index <= 10)
            Console.Write("{0} ", index);

Example while loop Repetition Statements

Yes No Suggest edit
Suggest Edit