Está en la página 1de 11

1

Estructuras de Control
Repetitivas
Programación 1

Semana 4
CS1100 - Introducción a Ciencia de la Computación Computer Science

Índice

1. Bucles
2. Ejercicios

2
CS1111 - Programación 1 Computer Science

1 Bucles

3
CS1111 - Programación 1 Computer Science

¿Qué es un bucle?

Son instrucciones que permiten que el flujo de ejecución repita una parte del
programa de acuerdo a una condición.

4
CS1111 - Programación 1 Computer Science

¿Cómo se implementa? Part 1


Algoritmo: Programa:
1. Mientras condición es verdad: 1 while condition:
1.1. Instrucción 1 2 instruction_1
1.2. Instrucción 2 3 instruction_2
1.3. … 4 …
1.4. Instrucción x 5 instruction_x

5
CS1111 - Programación 1 Computer Science

Ejemplo 1
Algoritmo: Programa:
1. Empiezo mi tarea 1 linea = 0
2. Mientras no escriba 5 líneas: 2 while linea < 5 :
2.1. Escribir frase 3 print("Education is the passport to the future")
2.2. Actualizo mi tarea 4 linea = linea + 1

Iteración linea linea < 5 resultado


1 0 True Education is the passport to the future

2 1 True Education is the passport to the future

3 2 True Education is the passport to the future

4 3 True Education is the passport to the future

5 4 True Education is the passport to the future

6 5 False
6
CS1111 - Programación 1 Computer Science

¿Cómo se implementa? Part 1


Algoritmo: Programa:
1. Para cada elemento: 1 for element in collection:
1.1. Instrucción 1 2 instruction_1
1.2. Instrucción 2 3 instruction_2
1.3. … 4 …
1.4. Instrucción x 5 instruction_x

7
CS1111 - Programación 1 Computer Science

Ejemplo 1
Algoritmo: Programa:
1. Para cada letra en ‘hola’ 1 for letra in "hola":
1.1. Escribir letra 2 print(letra)

Iteración letra resultado


1 h h

2 o o

3 l l

4 a a

8
CS1111 - Programación 1 Computer Science

2 Ejercicios

9
CS1111 - Programación 1 Computer Science

Resumen

● Las instrucciones repetitivas o bucles permiten que el flujo de ejecución


repita una parte del programa de acuerdo a una condición.

10
Gracias

11

También podría gustarte