Programming Course in C# ¡Free!

while + counter

 Friday, April 05, 2013 published by Exercises C#
Proposed exercise

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

Output



Solution


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

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