Академический Документы
Профессиональный Документы
Культура Документы
com
If - Else
IF : si Else: Else: sino
DELPHI (PASCAL)
c03 Sentencias de Control
Pablo Roncagliolo
CONDICION
La condicin es una expresin lgica, es decir, entrega un valor de verdad (booleano ) (booleano)
prb@2005
prb@2005
If - Else
CONDICIONES LOGICAS
Sea a y b variables numricas o constantes... a>b a<b a <> b a=b mayor menor distinto igual
If - Else
Ej. de CONDICIONES y EXPRESIONES LOGICAS
var a,b:integer ; a,b:integer; ok: ok:boolean; boolean; A:=3; B:=4; Ok:= true; ; Ok:=true (a > b) (a < b) (a <> b) (a = b) Ok Not( Not( Ok) Ok) (a < b) AND Ok (a = b) OR Ok Not( Not(Ok ) AND (a = b) Not (a > b) AND (a=b)
3 prb@2005
Sea OK una variable booleana OK verdadero o falso (true (true o false) false)
EXPRESIONES LOGICAS
AND OR NOT
prb@2005
false true true false true false true true false false
4
If - Else
SINTAXIS IF #1 IF CONDICIN then INSTRUCCIN; INSTRUCCIN; SINTAXIS IF #2 IF CONDICIN then begin INSTRUCCIN 1; INSTRUCCIN 2; INSTRUCCIN ...; INSTRUCCIN n; end; end;
If - Else
SINTAXIS IF #3 IF CONDICIN then INSTRUCCIN Else INSTRUCCIN; INSTRUCCIN;
prb@2005
prb@2005
PDFMAILER.COM Print and send PDF files as Emails with any application, ad-sponsored and free of charge www.pdfmailer.com
If - Else
SINTAXIS IF #4 IF CONDICIN then begin INSTRUCCIN 1; 1; INSTRUCCIN ...; INSTRUCCIN n; end Else begin INSTRUCCIN 1; 1; INSTRUCCIN ...; INSTRUCCIN n; end; end;
prb@2005
Case
SINTAXIS CASE #1 CASE Variable Ordinal of Valor 1:INSTRUCCIN ; 1:INSTRUCCIN; Valor 2:INSTRUCCIN ; 2:INSTRUCCIN; Valor ..:INSTRUCCIN ; ..:INSTRUCCIN; Valor n:INSTRUCCIN ; n:INSTRUCCIN; End; End;
ojo! No va ;
prb@2005
Case
SINTAXIS CASE #2 CASE Variable Ordinal of Valor 1:begin 1:begin
INSTRUCCIN; INSTRUCCIN; ...;
Case
Rango y mltiples valores, Ej.: A:integer; C:char; A:=3; CASE A of 1..10:INSTRUCCIN ; //rango 1 a 10 1..10:INSTRUCCIN; 11..20:INSTRUCCIN ; 11..20:INSTRUCCIN; End; End; c:=a; CASE c of a,A:INSTRUCCIN ; //valor a o A a,A:INSTRUCCIN; b,B:INSTRUCCIN ; b,B:INSTRUCCIN; c,C,d,D:INSTRUCCIN ; c,C,d,D:INSTRUCCIN; End; End;
10
While
While : mientras
While
SINTAXIS IF #1 WHILE CONDICIN DO INSTRUCCIN; INSTRUCCIN; SINTAXIS IF #2 WHILE CONDICIN DO begin INSTRUCCIN 1; INSTRUCCIN 2; INSTRUCCIN ...; INSTRUCCIN n; end; end;
CONDICION
La condicin es una expresin lgica, es decir, entrega un valor de verdad (booleano ) (booleano) El While utiliza condiciones al igual que el IFIF-ELSE.
prb@2005
11
prb@2005
12
PDFMAILER.COM Print and send PDF files as Emails with any application, ad-sponsored and free of charge www.pdfmailer.com
While
Ej, Ej, #1 i:=0; WHILE i<10 DO i:=i+1; i:=i+1; Ej. #2 i:=0; a:=1; WHILE (i<4) DO begin i:=i+1; a:=a*i; end; end;
prb@2005 13
While
Ej, Ej, #3 var begin write(Ingrese el n de notas que tiene:); readln(n); i:=0; suma:=0; WHILE i<n i<n DO begin i:=i+1; write(Ingrese nota ,i); readln(nota); suma:=suma+nota end; writeln(El promedio es:,suma/n); readln; end;
prb@2005 14
For
For : para
SETENCIA DE CONTROL DE CICLOS
Permite ejecutar un cierto ciclo o bucle de instrucciones, para una serie de valores asignados a una variable especfica.
For
SINTAXIS IF #1 FOR Variable:=valor1 TO valor2 DO INSTRUCCIN 1; SINTAXIS IF #2 FOR Variable:=valor1 TO valor2 DO begin INSTRUCCIN 1; INSTRUCCIN ...; INSTRUCCIN n; end; end;
prb@2005 16
VALORES ASIGNADOS
En cada ejecucin del ciclo, se asigna una valor a la variable de o de ciclo. de loop loop Estos valores se asignan en el rango definido por el programador y la variable de loop loop se incrementa o decrementa automticamente en cada ciclo.
VARIABLE DE LOOP
Es una variable de tipo integer . integer.
prb@2005
15
For
SINTAXIS IF #3 FOR Variable:=valor2 DOWNTO valor1 DO INSTRUCCIN 1; SINTAXIS IF #4 FOR Variable:=valor2 DOWNTO valor1 DO begin INSTRUCCIN 1; INSTRUCCIN ...; INSTRUCCIN n; end; end;
prb@2005 17
For
Ej, Ej, #1 FOR i:=0 TO 9 DO; Ej. #2 a:=1; FOR i:=1 TO 4 DO begin a:=a*i; end; end; Ej, Ej, #3 FOR i:=3 DOWNTO 1 DO write(al cuadrado es:,i*i);
prb@2005 18
PDFMAILER.COM Print and send PDF files as Emails with any application, ad-sponsored and free of charge www.pdfmailer.com
For
Ej, Ej, #4 var begin write(Ingrese el n de notas que tiene:); readln(n); suma:=0; FOR i:=1 to n DO begin write(Ingrese nota ,i); readln(nota); suma:=suma+nota end; writeln(El promedio es:,suma/n); readln; end; i,n:integer; suma, nota:double;
For
Ej, Ej, #6 Type A_NOMBRE: array[1..3] of string; Type A_EDAD: array[1..3] of integer;
end;
prb@2005 19 prb@2005
20
end;
For
Ej, Ej, #7
end;
prb@2005 21