Documentos de Académico
Documentos de Profesional
Documentos de Cultura
If - else
if (expresión) {
instrucción o bloque de intrucciones 1;
}
[else {
instrucción o bloque de intrucciones 2;
} ]
if (expresión 1) {
instrucción o bloque de instrucciones 1;
}
else if (expresión 2) {
instrucción o bloque de instrucciones 2;
}
else if (expresión 3) {
instrucción o bloque de instrucciones 3;
}
else {
intrucción o bloque de instrucciones 4;
}
using System;
class condicionalIF {
public static void Main() {
string myInput;
int myInt;
Console.Write("Please enter a number: ");
myInput = Console.ReadLine();
myInt = Int32.Parse(myInput);
// decisión MÚLTIPLE
if (myInt < 0 || myInt == 0) {
Console.WriteLine("el número {0} es menor o igual a
cero", myInt);
} else if (myInt > 0 && myInt <= 10) {
Console.WriteLine("el número {0} está entre 1 y 10",
myInt);
} else if (myInt > 10 && myInt <= 20) {
Console.WriteLine("el número {0} está entre 11 y 20",
myInt);
} else if (myInt > 20 && myInt <= 30) {
Console.WriteLine("el número {0} está entre 21 y 30",
myInt);
} else {
Console.WriteLine("el número {0} es mayor que 30",
myInt);
}
}
}