Ejercicio
While + Contador
Objetivo
Cree un programa en C# para mostrar los números del 1 al 10 en la pantalla, usando "while".
Código de Ejemplo
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
}
}
}