ESTRUCTURAS DE CONTROL SELECTIVA LUIS OCTAVIO BUSTAMANTE Docente Colegio de la UPB
CONDICIONAL SI Es una función de tipo lógico que sirve para evaluar una condición (pregunta) y obtener una respuesta de verdadero o falso.
OPERADORES DE COMPARACIÓN > Mayor >= Mayor Igual < Menor <= Menor e igual = igual <> Diferente
SENTENCIA SIMPLE Sintaxis If (condición) then acciones End if Condición Acción SI
Ejemplo Module Module1 Sub Main() Dim edad As Integer Console.WriteLine("Ingrese una edad: ") edad = Console.ReadLine If (edad >= 18) Then Console.WriteLine("Tiene cédula...") End If Console.ReadLine() End Sub End Module
SENTENCIA DOBLE Sintaxis If (condición) then Acciones Else Acciones End if Condición Acción SI Acción NO
Module Module1 Sub Main() Dim valor As Single Console.WriteLine("Digite un número: ") valor = Console.ReadLine If valor > 0 Then Console.WriteLine("El número es POSITIVO") Else Console.WriteLine("El número es NEGATIVO") End If Console.ReadLine() End Sub End Module
SENTENCIA MULTIPLE Sintaxis If (condición) then Acciones ElseIf (condición 2) then Acciones ElseIf (condición 2) then Acciones End if
Condición Acción SINO Condición Acción SINO Condición
Module Module1 Sub Main() Dim nota As Double Console.WriteLine("Digite la nota definitiva: ") nota = Console.ReadLine If (nota >= 3.5) Then Console.WriteLine(“Estudiante GANA") ElseIf (nota < 2) Then Console.WriteLine(“Estudiante PIERDE") Else Console.WriteLine(“Estudiante REFUERZA") End If Console.ReadLine() End Sub End Module