Friday 20 November 2015

The do while loop in asp.net

Introduction:

C# provides four different loops (for, while, do...while, and foreach) that allow us to execute a block of code repeatedly until a certain condition is met.I will explain about the do while loop here.

Explanation:

The do while  loop’s test condition is evaluated after the body of the loop has been executed. Consequently,do...while loops are useful for situations in which a block of statements must be executed at least one

If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop execute again. This process repeats until the given condition becomes false.
time, as in this example:

class Program
{
    static void Main()
    {
    int[] ids = new int[] { 6, 7, 8, 10 };

    //
    // Use do-while loop to sum numbers in 4-element array.
    //
    int sum = 0;
    int i = 0;
    do
    {
        sum += ids[i];
        i++;
    } while (i < 4);

    System.Console.WriteLine(sum);
    }
}


No comments:

Post a Comment