While + Counter Learn programming C#

Lesson:

Flow Control


Exercise:

While + Counter


Objetive:

Create a C# program to display the numbers 1 to 10 on the screen using "while".


Code:

using System;
public class Exercise22
{
    public static void Main()
    {
        int n = 1;

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

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.