Created
September 27, 2023 13:37
-
-
Save diegoolipa/fb2ad0a9f1621c2a668521a25ba61be9 to your computer and use it in GitHub Desktop.
Ciclo While and Swith Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://aka.ms/new-console-template for more information | |
bool salir = false; | |
while (!salir) | |
{ | |
Console.WriteLine("=================="); | |
Console.WriteLine("Nombre: Diego Lipa"); | |
Console.WriteLine("=================="); | |
Console.WriteLine("Elije una opción: "); | |
Console.WriteLine("1 - Saludar"); | |
Console.WriteLine("2 - Despedir"); | |
Console.WriteLine("3 - Salir"); | |
// Leer la opción ingresada por el usuario | |
int opcion = int.Parse(Console.ReadLine()); | |
switch (opcion) | |
{ | |
case 1: | |
Console.WriteLine("Hola, ¡bienvenido!"); | |
break; | |
case 2: | |
Console.WriteLine("Adiós, ¡hasta luego!"); | |
break; | |
case 3: | |
Console.WriteLine("Saliendo del programa..."); | |
salir = true; // Establece la bandera para salir del bucle | |
break; | |
default: | |
Console.WriteLine("Opción no válida. Por favor, elije una opción válida."); | |
break; | |
} | |
} | |
Console.WriteLine("Fin del programa."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment