43
Estructuras de Control Jhedson Ninahuamán Chávez Consultor & MCTS for SQL Server [email protected] 1. Crear programas en el lenguaje C# utilizando estructuras de control 2. Estructuras condicionales: If, If-Else, If anidados, Swich 3. Estructuras repetitivas: While, Do ….While, for Objetivos

Estructuras de Control

Embed Size (px)

DESCRIPTION

Estructuras de Control - C#

Citation preview

Automating Server-based Build, QA & Test withVisual Studio 2012

Estructuras de ControlJhedson Ninahuamn ChvezConsultor & MCTS for SQL [email protected]

Crear programas en el lenguaje C# utilizando estructuras de controlEstructuras condicionales: If, If-Else, If anidados, SwichEstructuras repetitivas: While, Do .While, for

Objetivos4/13/2014 7:23 AM 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

1ESTRUCTURAS DE CONTROL (Control Flow)Secuencia de instrucciones que se ejecutan en un programaCondicionales (Conditionals) y bucles (loops)

Sentencia 1Sentencia 1Sentencia 1Sentencia 1Boolean 1Sentencia 1Sentencia 3Sentencia 2Boolean 2truetruefalsefalseFlujo de control secuencialFlujo de control condicional y bucles2CONDICIONALES

SENTENCIA IFUna instruccin if identifica que sentencia se tiene que ejecutar en funcin del valor de una expresin Booleanif (expresin Boolean){ }Las sentencias a ejecutar estan dentro del cuerpo o bloqueSe evalua la expresin

DemoNombre del pry: ConsoleSentenciaIF

SENTENCIA IF - ELSESi el valor de la expresin booleana es True, ejecuta sentencia TSi el valor de la expresin booleana es False, ejecuta sentencia F

if (expresin boolean){Sentencia(s) T;}Else{Sentencia(s) F;}expresin booleanSentencia TSentencia FTrueFalse

DemoNombre del pry: ConsoleSentenciaIFElse

IF anidadoOcurre cuando encontramos en el bloque de instrucciones correspondiente a la seccin del if o del else otras sentencias if o if - else

DemoNombre del pry: ConsoleSentenciaIFAnidadoSentencia switch

Dato de Entrada : 1 Datos de Salida : ROJO

switch (variable) {case valor: //cdigo break;case otrovalor: //cdigo break;default: //cdigobreak;}DemoNombre del pry: ConsoleSentenciaSwitchLoops (Bucle)Problema: Supongamos que usted necesita imprimir una cadena (por ejemplo, "Bienvenido a C#!") Cien veces. Sera tedioso tener que escribir la siguiente declaracin cien veces:

Entonces, cmo resolver este problema? Console.WriteLine("Bienvenido a C#");Problema

100 veces11Blucle while

DemoNombre del pry: ConsoleWhilewhile (Condicion-continuacin-bucle){//Cuerpo del bucleSentencia(s);}

Condicion-continuacin-bucleSentencia(s)Cuerpo del buclefalsetrue(Count =0) ?Console.WriteLine(Bienvenido a C#);falsetrueCount =0;Sintaxis

Seguimiento al bucle WhileInicializa contador

(Count