SlideShare une entreprise Scribd logo
1  sur  17
Curso de Lógica y Programación Tema 4: Ejecución condicional de instrucciones María Claudia Lara Universidad de San Buenaventura Cali Primer Semestre de 2008
Instrucción  IF/THEN/ELSE  (1) ,[object Object],[object Object],[object Object],IF <prueba> THEN  begin   <instrucción-1>; end ELSE begin   <instrucción-2>; end;
Instrucción  IF/THEN/ELSE  (2) ,[object Object],[object Object],[object Object],[object Object],IF <prueba> THEN  begin   <instrucción-1>; end ELSE begin   <instrucción-2>; end;
Instrucción  IF/THEN/ELSE  (3) ,[object Object],IF <prueba> THEN  begin <instrucción-1>; end ELSE begin <instrucción-2>; end;
Instrucción  IF/THEN/ELSE  (4) Ahora se verá una nueva tarea que, convenientemente, implica la instrucción IF/THEN/ELSE. Supóngase que se desea programar a Karel para que corra una carrera de obstáculos de una milla, en donde secciones verticales de pared representan las vallas. Se sabe que las vallas tienen una altura de tan sólo una cuadra, pero pueden estar colocadas al azar entre cualesquiera dos esquinas en el curso de la carrera. Uno de los diversos cursos para esta carrera se ilustra en la figura. Situación inicial Situación final y trayectoria seguida por Karel
Instrucción  IF/THEN/ELSE  (5) beginning-of-execution corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; turnoff; end-of-execution define-new-instruction corre-a-zancadas as begin IF front-is-clear THEN begin   move; end ELSE begin   brinca-la-valla; end; end; define-new-instruction brinca-la-valla as begin brinca; move; baja; end; define-new-instruction brinca as begin turnleft; move; turnright; end; define-new-instruction baja as begin turnright; move; turnleft; end; define-new-instruction turnright as  begin turnleft; turnleft; turnleft; end; Se debe programar a Karel para moverse en línea recta mientras pueda, y brincando las vallas sólo cuando deba hacerlo. Utilizando el refinamiento paso por paso.
Instrucción  IF/THEN/ELSE  (6) define-new-instruction corre-a-zancadas as begin IF front-is-clear THEN begin   move; end ELSE begin   brinca-la-valla; end; end; beginning-of-execution corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; turnoff; end-of-execution end-of-program beginning-of-program define-new-instruction turnright as  begin turnleft; turnleft; turnleft; end; define-new-instruction baja as begin turnright; move; turnleft; end; define-new-instruction brinca as begin turnleft; move; turnright; end; define-new-instruction brinca-la-valla as begin brinca; move; baja; end; El orden de las instrucciones se debe invertir al incorporarlas al programa completo
Instrucciones IF incluidas  (1) ,[object Object],[object Object]
Instrucciones IF incluidas  (2) ,[object Object],Situación inicial Situación final Existen aproximadamente 200 trillones de campos distintos que el programa puede replantar en forma correcta (existen 3 distintas posibilidades y hay 30 esquinas en el campo. El número total de campos diferentes es 3 a la 30, en donde 3 se multiplica por sí mismo 30 veces. El número exacto de campos diferentes es 205,891,132,094,649)
Instrucciones IF incluidas  (3) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Situación inicial Situación final La instrucción IF incluida se encuentra dentro de la cláusula ELSE del IF externo.
Instrucciones IF incluidas  (4) ,[object Object],[object Object],[object Object]
Instrucciones IF incluidas  (5) ,[object Object],[object Object],[object Object]
Instrucciones IF incluidas  (6) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Taller ,[object Object],[object Object],[object Object]
Taller ,[object Object],[object Object],[object Object]
Taller ,[object Object]
Taller ,[object Object]

Contenu connexe

Tendances (8)

INVESTIGACION DE ELEMENTOS Y CODIGOS DE C++
INVESTIGACION DE ELEMENTOS Y CODIGOS DE C++INVESTIGACION DE ELEMENTOS Y CODIGOS DE C++
INVESTIGACION DE ELEMENTOS Y CODIGOS DE C++
 
c++
c++c++
c++
 
Power
PowerPower
Power
 
C docx22 (1)
C docx22 (1)C docx22 (1)
C docx22 (1)
 
ESTRUCTURAS REPETITIVAS
ESTRUCTURAS REPETITIVASESTRUCTURAS REPETITIVAS
ESTRUCTURAS REPETITIVAS
 
Diego alexis 8
Diego alexis 8Diego alexis 8
Diego alexis 8
 
Ejercicio 8
Ejercicio 8Ejercicio 8
Ejercicio 8
 
Programación Introducción al lenguaje C
Programación Introducción al lenguaje CProgramación Introducción al lenguaje C
Programación Introducción al lenguaje C
 

Similaire à 07 Logica Programacion (7)

08 Logica Programacion
08 Logica Programacion08 Logica Programacion
08 Logica Programacion
 
Lab etap4
Lab etap4Lab etap4
Lab etap4
 
Teoria
TeoriaTeoria
Teoria
 
Instrucciones Básicas
Instrucciones BásicasInstrucciones Básicas
Instrucciones Básicas
 
Estructuras de control C++
Estructuras de control C++Estructuras de control C++
Estructuras de control C++
 
While karel
While karelWhile karel
While karel
 
If then o if then else
If then o if then elseIf then o if then else
If then o if then else
 

Dernier

Proyecto de aprendizaje dia de la madre MINT.pdf
Proyecto de aprendizaje dia de la madre MINT.pdfProyecto de aprendizaje dia de la madre MINT.pdf
Proyecto de aprendizaje dia de la madre MINT.pdf
patriciaines1993
 
TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...
TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...
TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...
jlorentemartos
 
🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx
🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx
🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx
EliaHernndez7
 

Dernier (20)

Prueba de evaluación Geografía e Historia Comunidad de Madrid 2º de la ESO
Prueba de evaluación Geografía e Historia Comunidad de Madrid 2º de la ESOPrueba de evaluación Geografía e Historia Comunidad de Madrid 2º de la ESO
Prueba de evaluación Geografía e Historia Comunidad de Madrid 2º de la ESO
 
Proyecto de aprendizaje dia de la madre MINT.pdf
Proyecto de aprendizaje dia de la madre MINT.pdfProyecto de aprendizaje dia de la madre MINT.pdf
Proyecto de aprendizaje dia de la madre MINT.pdf
 
Posición astronómica y geográfica de Europa.pptx
Posición astronómica y geográfica de Europa.pptxPosición astronómica y geográfica de Europa.pptx
Posición astronómica y geográfica de Europa.pptx
 
Power Point E. S.: Los dos testigos.pptx
Power Point E. S.: Los dos testigos.pptxPower Point E. S.: Los dos testigos.pptx
Power Point E. S.: Los dos testigos.pptx
 
TIENDAS MASS MINIMARKET ESTUDIO DE MERCADO
TIENDAS MASS MINIMARKET ESTUDIO DE MERCADOTIENDAS MASS MINIMARKET ESTUDIO DE MERCADO
TIENDAS MASS MINIMARKET ESTUDIO DE MERCADO
 
PP_Comunicacion en Salud: Objetivación de signos y síntomas
PP_Comunicacion en Salud: Objetivación de signos y síntomasPP_Comunicacion en Salud: Objetivación de signos y síntomas
PP_Comunicacion en Salud: Objetivación de signos y síntomas
 
Lecciones 06 Esc. Sabática. Los dos testigos
Lecciones 06 Esc. Sabática. Los dos testigosLecciones 06 Esc. Sabática. Los dos testigos
Lecciones 06 Esc. Sabática. Los dos testigos
 
Los dos testigos. Testifican de la Verdad
Los dos testigos. Testifican de la VerdadLos dos testigos. Testifican de la Verdad
Los dos testigos. Testifican de la Verdad
 
TRABAJO FINAL TOPOGRAFÍA COMPLETO DE LA UPC
TRABAJO FINAL TOPOGRAFÍA COMPLETO DE LA UPCTRABAJO FINAL TOPOGRAFÍA COMPLETO DE LA UPC
TRABAJO FINAL TOPOGRAFÍA COMPLETO DE LA UPC
 
FUERZA Y MOVIMIENTO ciencias cuarto basico.ppt
FUERZA Y MOVIMIENTO ciencias cuarto basico.pptFUERZA Y MOVIMIENTO ciencias cuarto basico.ppt
FUERZA Y MOVIMIENTO ciencias cuarto basico.ppt
 
Louis Jean François Lagrenée. Erotismo y sensualidad. El erotismo en la Hist...
Louis Jean François Lagrenée.  Erotismo y sensualidad. El erotismo en la Hist...Louis Jean François Lagrenée.  Erotismo y sensualidad. El erotismo en la Hist...
Louis Jean François Lagrenée. Erotismo y sensualidad. El erotismo en la Hist...
 
Feliz Día de la Madre - 5 de Mayo, 2024.pdf
Feliz Día de la Madre - 5 de Mayo, 2024.pdfFeliz Día de la Madre - 5 de Mayo, 2024.pdf
Feliz Día de la Madre - 5 de Mayo, 2024.pdf
 
activ4-bloque4 transversal doctorado.pdf
activ4-bloque4 transversal doctorado.pdfactiv4-bloque4 transversal doctorado.pdf
activ4-bloque4 transversal doctorado.pdf
 
TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...
TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...
TEMA 14.DERIVACIONES ECONÓMICAS, SOCIALES Y POLÍTICAS DEL PROCESO DE INTEGRAC...
 
SESION DE PERSONAL SOCIAL. La convivencia en familia 22-04-24 -.doc
SESION DE PERSONAL SOCIAL.  La convivencia en familia 22-04-24  -.docSESION DE PERSONAL SOCIAL.  La convivencia en familia 22-04-24  -.doc
SESION DE PERSONAL SOCIAL. La convivencia en familia 22-04-24 -.doc
 
🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx
🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx
🦄💫4° SEM32 WORD PLANEACIÓN PROYECTOS DARUKEL 23-24.docx
 
Tema 11. Dinámica de la hidrosfera 2024
Tema 11.  Dinámica de la hidrosfera 2024Tema 11.  Dinámica de la hidrosfera 2024
Tema 11. Dinámica de la hidrosfera 2024
 
1ro Programación Anual D.P.C.C planificación anual del área para el desarroll...
1ro Programación Anual D.P.C.C planificación anual del área para el desarroll...1ro Programación Anual D.P.C.C planificación anual del área para el desarroll...
1ro Programación Anual D.P.C.C planificación anual del área para el desarroll...
 
Tema 17. Biología de los microorganismos 2024
Tema 17. Biología de los microorganismos 2024Tema 17. Biología de los microorganismos 2024
Tema 17. Biología de los microorganismos 2024
 
ACERTIJO LA RUTA DEL MARATÓN OLÍMPICO DEL NÚMERO PI EN PARÍS. Por JAVIER SOL...
ACERTIJO LA RUTA DEL MARATÓN OLÍMPICO DEL NÚMERO PI EN  PARÍS. Por JAVIER SOL...ACERTIJO LA RUTA DEL MARATÓN OLÍMPICO DEL NÚMERO PI EN  PARÍS. Por JAVIER SOL...
ACERTIJO LA RUTA DEL MARATÓN OLÍMPICO DEL NÚMERO PI EN PARÍS. Por JAVIER SOL...
 

07 Logica Programacion

  • 1. Curso de Lógica y Programación Tema 4: Ejecución condicional de instrucciones María Claudia Lara Universidad de San Buenaventura Cali Primer Semestre de 2008
  • 2.
  • 3.
  • 4.
  • 5. Instrucción IF/THEN/ELSE (4) Ahora se verá una nueva tarea que, convenientemente, implica la instrucción IF/THEN/ELSE. Supóngase que se desea programar a Karel para que corra una carrera de obstáculos de una milla, en donde secciones verticales de pared representan las vallas. Se sabe que las vallas tienen una altura de tan sólo una cuadra, pero pueden estar colocadas al azar entre cualesquiera dos esquinas en el curso de la carrera. Uno de los diversos cursos para esta carrera se ilustra en la figura. Situación inicial Situación final y trayectoria seguida por Karel
  • 6. Instrucción IF/THEN/ELSE (5) beginning-of-execution corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; turnoff; end-of-execution define-new-instruction corre-a-zancadas as begin IF front-is-clear THEN begin move; end ELSE begin brinca-la-valla; end; end; define-new-instruction brinca-la-valla as begin brinca; move; baja; end; define-new-instruction brinca as begin turnleft; move; turnright; end; define-new-instruction baja as begin turnright; move; turnleft; end; define-new-instruction turnright as begin turnleft; turnleft; turnleft; end; Se debe programar a Karel para moverse en línea recta mientras pueda, y brincando las vallas sólo cuando deba hacerlo. Utilizando el refinamiento paso por paso.
  • 7. Instrucción IF/THEN/ELSE (6) define-new-instruction corre-a-zancadas as begin IF front-is-clear THEN begin move; end ELSE begin brinca-la-valla; end; end; beginning-of-execution corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; corre-a-zancadas; turnoff; end-of-execution end-of-program beginning-of-program define-new-instruction turnright as begin turnleft; turnleft; turnleft; end; define-new-instruction baja as begin turnright; move; turnleft; end; define-new-instruction brinca as begin turnleft; move; turnright; end; define-new-instruction brinca-la-valla as begin brinca; move; baja; end; El orden de las instrucciones se debe invertir al incorporarlas al programa completo
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.