Objective
Write a C# program to display the numbers 1 to 10 on the screen using "while".
Write Your C# Exercise
C# Exercise Example
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
int counter = 1; // Initializing the counter variable to 1
// Using a while loop to display numbers from 1 to 10
while (counter <= 10) // The loop will continue as long as counter is less than or equal to 10
{
// Displaying the current value of counter
Console.WriteLine(counter); // Printing the current number
counter++; // Incrementing the counter by 1 after each iteration
}
}
}
More C# Programming Exercises of Flow Control
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
In this C# exercise, you will learn how to write a program that asks the user to enter a number and then displays its multiplication table using a while loop. The ...
In this C# exercise, you will learn how to write a program that displays the odd numbers from 15 down to 7 using a while loop. The while loop is a control stru...
In this C# exercise, you will learn how to write a program that asks the user to enter an undetermined amount of numbers (until 0 is entered) and displays the total sum of t...
In this C# exercise, you will learn how to write a program that prompts the user to enter two numbers and determines whether both numbers are negative or not. This type of p...
In this C# exercise, you will learn how to write a program that prompts the user to enter two numbers and then determines whether both numbers are negative, only one is nega...
In this exercise, you will learn how to use the modulo operator % to find numbers between 1 and 500 that are divisible by both 3 and 5. The program will...