SlideShare una empresa de Scribd logo
1 de 23
Estructuras de
Repetición

Estructuras de Repetición

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

En la mayoría de los problemas a
resolver pueden existir procesos
que se hacen una sola vez y
procesos que se repiten varias
veces.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

Podemos codificar problemas donde las acciones se ejecutan
sólo una vez, pero la mayoría de las veces

necesitamos repetir varias veces esas acciones
La estructura de repetición nos permite indicar las acciones que
queremos repetir, un número determinado o indeterminado de
veces.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
Veamos el siguiente ejercicio:
Leer los datos de un grupo de personas. Imprimir los
nombres solo de aquellos que sean del sexo masculino.

Observa que debemos repetir la lectura y chequeo de
los datos, tantas veces como personas haya en el
grupo.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
Se utilizaría entonces la siguiente codificación:

Se va a
REPETIR el
proceso de
leer los datos
mientras
haya más
datos que
leer y se va
escribiendo el
reporte en la
hoja de
cálculo.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
Observa el uso que se le da aquí a la caja de
diálogo msgbox.

La caja de diálogo que aparece es:

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
Hay dos tipos de estructuras de repetición:
La primera es aquella en la cual el número de repeticiones
es desconocido y se hará mientras se cumpla cierta
condición. Se conoce como Repetición Condicionada.

La segunda es aquella en donde se tiene perfectamente
establecido el número de veces que un grupo de acciones
se va a ejecutar (20, 5, 2 veces). Esta se conoce como
Repetición Indexada.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
Repetición un número indeterminado de veces
La primera forma de estructura repetitiva es para
aquellos casos donde no se conoce el número de
repeticiones o iteraciones en que se va a ejecutar una
acción o un bloque de acciones.
Estructura
Mientras se cumpla una condición
...
fin-mientras

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
En Visual Basic Sería:

While (condición)
acción1
accion2
...
Wend

Las instrucciones acción1, acción2 hasta la instrucción
Wend se repetirán mientras la condición sea verdadera.
Debemos identificar la condición de parada, la cual
indica cuándo termina la repetición.

Se trata entonces, de una toma de decisión para repetir un
proceso mientras se cumpla una condición, y salir de él al
momento de no cumplirse.
by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Veamos
el
siguiente
ejemplo:

Estructuras de
Repetición

La variable numero que
controla la condición de
parada debe ser
inicializada antes de la
repetición y modificada
dentro de la repetición.

La repetición puede
no ejecutarse nunca.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
La respuesta es :

Si no se coloca esa
instrucción ocurren Infinitas
repeticiones!!!!

Al no modificarse la variable la condición
es siempre verdadera y por lo tanto la
repetición no termina.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

¿Y qué pasaría en
este caso?

contador

Contador<> 0

5

SI

5-3 = 2

SI

2-3 = -1

SI

-1 -3 = -4

SI

-4 -3 = -7

SI

Respuesta: Nunca se sale de la repetición...
by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición
¿Qué vemos entonces nuestro programa?
Inicialización de la
variable Respuesta

Condición de parada:
Respuesta = VbNo

Modificación de la
variable Respuesta

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

¿Cómo resolvemos el siguiente enunciado?

Dado el precio de varios productos, codifique las
instrucciones para calcular el monto final a pagar por
cada uno, sabiendo que se hace un descuento de
acuerdo a la siguiente tabla:
precio (Bs.)
> 10
<= 10

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

descuento (%)
6
5

mrodriguez@unimet.edu.ve
Codificación en VBA:

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

Estructuras de
Repetición

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

Si a este enunciado le agregamos :

Se desea un total de los montos a pagar
por todos los productos.
¿Cómo calculamos ese monto total?
Deberíamos sumar cada uno de los montos a pagar por
producto a medida que los vayamos calculando.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

Y si además le agregamos :

Se desea saber cuanto clientes fueron
atendidos.
¿Cómo contamos?
Utilizando una variable especial que llamamos contador a la
cual le sumamos 1 en cada vuelta del ciclo de cálculo.

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

El reporte de los acumuladores y
contadores se debe hacer
siempre al finalizar el ciclo while
by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

Y si además le agregamos :

Se desea saber conocer el monto
promedio en Bs pagado por cliente.
¿Cómo lo calculamos?
Para calcular el promedio debemos dividir el monto total
pagado por los clientes entre el numero de clientes
atendidos, este cálculo se hace al salir del ciclo:
Prom = acuMonto/cont
by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve
Estructuras de
Repetición

Pasemos ahora a estudiar las repeticiones indexadas….

by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative
Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License.

mrodriguez@unimet.edu.ve

Más contenido relacionado

Último

guía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Josephguía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan JosephBRAYANJOSEPHPEREZGOM
 
International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)GDGSucre
 
Presentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxPresentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxLolaBunny11
 
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...silviayucra2
 
Trabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíaTrabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíassuserf18419
 
pruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITpruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITMaricarmen Sánchez Ruiz
 
Desarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfDesarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfJulian Lamprea
 
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricGlobal Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricKeyla Dolores Méndez
 
EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveFagnerLisboa3
 
Proyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptxProyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptx241521559
 

Último (10)

guía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Josephguía de registro de slideshare por Brayan Joseph
guía de registro de slideshare por Brayan Joseph
 
International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)International Women's Day Sucre 2024 (IWD)
International Women's Day Sucre 2024 (IWD)
 
Presentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptxPresentación guía sencilla en Microsoft Excel.pptx
Presentación guía sencilla en Microsoft Excel.pptx
 
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
POWER POINT YUCRAElabore una PRESENTACIÓN CORTA sobre el video película: La C...
 
Trabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnologíaTrabajo Mas Completo De Excel en clase tecnología
Trabajo Mas Completo De Excel en clase tecnología
 
pruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNITpruebas unitarias unitarias en java con JUNIT
pruebas unitarias unitarias en java con JUNIT
 
Desarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdfDesarrollo Web Moderno con Svelte 2024.pdf
Desarrollo Web Moderno con Svelte 2024.pdf
 
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft FabricGlobal Azure Lima 2024 - Integración de Datos con Microsoft Fabric
Global Azure Lima 2024 - Integración de Datos con Microsoft Fabric
 
EPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial UninoveEPA-pdf resultado da prova presencial Uninove
EPA-pdf resultado da prova presencial Uninove
 
Proyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptxProyecto integrador. Las TIC en la sociedad S4.pptx
Proyecto integrador. Las TIC en la sociedad S4.pptx
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Repetición condicionada en VBA

  • 1. Estructuras de Repetición Estructuras de Repetición by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 2. Estructuras de Repetición En la mayoría de los problemas a resolver pueden existir procesos que se hacen una sola vez y procesos que se repiten varias veces. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 3. Estructuras de Repetición Podemos codificar problemas donde las acciones se ejecutan sólo una vez, pero la mayoría de las veces necesitamos repetir varias veces esas acciones La estructura de repetición nos permite indicar las acciones que queremos repetir, un número determinado o indeterminado de veces. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 4. Estructuras de Repetición Veamos el siguiente ejercicio: Leer los datos de un grupo de personas. Imprimir los nombres solo de aquellos que sean del sexo masculino. Observa que debemos repetir la lectura y chequeo de los datos, tantas veces como personas haya en el grupo. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 5. Estructuras de Repetición Se utilizaría entonces la siguiente codificación: Se va a REPETIR el proceso de leer los datos mientras haya más datos que leer y se va escribiendo el reporte en la hoja de cálculo. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 6. Estructuras de Repetición Observa el uso que se le da aquí a la caja de diálogo msgbox. La caja de diálogo que aparece es: by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 7. Estructuras de Repetición Hay dos tipos de estructuras de repetición: La primera es aquella en la cual el número de repeticiones es desconocido y se hará mientras se cumpla cierta condición. Se conoce como Repetición Condicionada. La segunda es aquella en donde se tiene perfectamente establecido el número de veces que un grupo de acciones se va a ejecutar (20, 5, 2 veces). Esta se conoce como Repetición Indexada. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 8. Estructuras de Repetición Repetición un número indeterminado de veces La primera forma de estructura repetitiva es para aquellos casos donde no se conoce el número de repeticiones o iteraciones en que se va a ejecutar una acción o un bloque de acciones. Estructura Mientras se cumpla una condición ... fin-mientras by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 9. Estructuras de Repetición En Visual Basic Sería: While (condición) acción1 accion2 ... Wend Las instrucciones acción1, acción2 hasta la instrucción Wend se repetirán mientras la condición sea verdadera. Debemos identificar la condición de parada, la cual indica cuándo termina la repetición. Se trata entonces, de una toma de decisión para repetir un proceso mientras se cumpla una condición, y salir de él al momento de no cumplirse. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 10. Veamos el siguiente ejemplo: Estructuras de Repetición La variable numero que controla la condición de parada debe ser inicializada antes de la repetición y modificada dentro de la repetición. La repetición puede no ejecutarse nunca. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 11. Estructuras de Repetición La respuesta es : Si no se coloca esa instrucción ocurren Infinitas repeticiones!!!! Al no modificarse la variable la condición es siempre verdadera y por lo tanto la repetición no termina. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 12. Estructuras de Repetición ¿Y qué pasaría en este caso? contador Contador<> 0 5 SI 5-3 = 2 SI 2-3 = -1 SI -1 -3 = -4 SI -4 -3 = -7 SI Respuesta: Nunca se sale de la repetición... by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 13. Estructuras de Repetición ¿Qué vemos entonces nuestro programa? Inicialización de la variable Respuesta Condición de parada: Respuesta = VbNo Modificación de la variable Respuesta by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 14. Estructuras de Repetición ¿Cómo resolvemos el siguiente enunciado? Dado el precio de varios productos, codifique las instrucciones para calcular el monto final a pagar por cada uno, sabiendo que se hace un descuento de acuerdo a la siguiente tabla: precio (Bs.) > 10 <= 10 by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. descuento (%) 6 5 mrodriguez@unimet.edu.ve
  • 15. Codificación en VBA: by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. Estructuras de Repetición mrodriguez@unimet.edu.ve
  • 16. Estructuras de Repetición Si a este enunciado le agregamos : Se desea un total de los montos a pagar por todos los productos. ¿Cómo calculamos ese monto total? Deberíamos sumar cada uno de los montos a pagar por producto a medida que los vayamos calculando. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 17. Estructuras de Repetición by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 18. Estructuras de Repetición Y si además le agregamos : Se desea saber cuanto clientes fueron atendidos. ¿Cómo contamos? Utilizando una variable especial que llamamos contador a la cual le sumamos 1 en cada vuelta del ciclo de cálculo. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 19. Estructuras de Repetición by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 20. Estructuras de Repetición El reporte de los acumuladores y contadores se debe hacer siempre al finalizar el ciclo while by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 21. Estructuras de Repetición Y si además le agregamos : Se desea saber conocer el monto promedio en Bs pagado por cliente. ¿Cómo lo calculamos? Para calcular el promedio debemos dividir el monto total pagado por los clientes entre el numero de clientes atendidos, este cálculo se hace al salir del ciclo: Prom = acuMonto/cont by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 22. Estructuras de Repetición by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve
  • 23. Estructuras de Repetición Pasemos ahora a estudiar las repeticiones indexadas…. by Dpto de Programacion y Tecnologia Educativa UNIMET is licensed under a Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0 Unported License. mrodriguez@unimet.edu.ve