Link Search Menu Expand Document

ad


do - while statement

The do statement executes a statement repeatedly while a specified expression evaluates to false.

  • Write the following code :
using System;

namespace LearnCSharp
{
    class Program
    {
        static void Main(string[] args)
        { 
            int sum = 0;
            int i = 1;
            do
            {
                sum = sum + i;
                i++;
            }
            while (i < 11);

            Console.WriteLine($"The sum of the numbers 1 to 10 is : {sum}");
        }
    }
}
  • Run the application in the Console Window

Output in Console Window

The sum of the numbers 1 to 10 is : 55

Bob Tabor Videos

Courtesy Microsoft and Bob Tabor


NOTE - These videos are a little dated, Visual Studio 2013/2015 is being used here. But the principles are basically the same.


While Iteration Statement


ad



Copyright © 2020 Ray Consulting Limited - Coding Skills.IO.