Tag Archives: #mastery22

Mastery 22

When to use what type of repetition in a program:
Introduction
Computers excel at repeating sections of code over and over. They can very quickly do thousands of similar computations, one after the other. (On a computer with more than one processor, several computations may even be able to be done at the same time.) The main way to repeat a section of code in a program is with a “loop” construct. We sometimes speak of looping through a section of code when we are talking about repeating it over and over.

The FOR Loop
The WHILE Loop
The DO..WHILE Loop
Properties of Loops

Link to the page:
http://cis.stvincent.edu/html/tutorials/swd/basic/control/repetition/
link too a video:
https://www.youtube.com/watch?v=4Mu-6U103_8

TC1017 22

MASTERY 22 When to use what type of repetition in a program

CUANDO UTILIZAR QUE TIPO DE REPETICIÓN USAR EN UN PROGRAMA

Ya hemos visto todos los tipos de repetición de un programa. Eso de cuando utilizarlos va depende del tipo del algoritmo que quieras utilizar. También es posible combinarlos para un código más grande. Pero OJO, no todos los tipos puedan funcionar. Hay que dejar claro los 3 tipos de repetición y con sus ejemplos debido a que ya se había explicado anteriormente en algunos WSQ y Masteries.

El uso de “while” se utiliza para que una operación se haga una y otra vez hasta que la condición se rompa. Un ejemplo sería el Método Babilónico. La variable “z” se rompe cuando este es igual a la variable “y”.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

El uso de “for” tiene muchos usos, pero lo principal es que establece ciertos límites y se hará la operación tantas veces hasta llegar a ese límite. Un ejemplo sería el de la Mastery 20 con el de las potencias. Se establece un límite en “b”, es decir, se hará “b” la misma operación.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

Y el uso de la recursión algorítmica  que se define la función a sí misma, es decir, se llama la función dentro de su misma función. El ejemplo sería el del Gran Común Divisor de la WSQ12. Dependiendo de los valores de “a” y “b”, se restará esos argumentos dependiendo de la condición llamando la función en sí.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

CUANDO UTILIZAR QUE TIPO DE REPETICIÓN USAR EN UN PROGRAMA

Ya hemos visto todos los tipos de repetición de un programa. Eso de cuando utilizarlos va depende del tipo del algoritmo que quieras utilizar. También es posible combinarlos para un código más grande. Pero OJO, no todos los tipos puedan funcionar. Hay que dejar claro los 3 tipos de repetición y con sus ejemplos debido a que ya se había explicado anteriormente en algunos WSQ y Masteries.

El uso de “while” se utiliza para que una operación se haga una y otra vez hasta que la condición se rompa. Un ejemplo sería el Método Babilónico. La variable “z” se rompe cuando este es igual a la variable “y”.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

El uso de “for” tiene muchos usos, pero lo principal es que establece ciertos límites y se hará la operación tantas veces hasta llegar a ese límite. Un ejemplo sería el de la Mastery 20 con el de las potencias. Se establece un límite en “b”, es decir, se hará “b” la misma operación.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

Y el uso de la recursión algorítmica  que se define la función a sí misma, es decir, se llama la función dentro de su misma función. El ejemplo sería el del Gran Común Divisor de la WSQ12. Dependiendo de los valores de “a” y “b”, se restará esos argumentos dependiendo de la condición llamando la función en sí.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

CUANDO UTILIZAR QUE TIPO DE REPETICIÓN USAR EN UN PROGRAMA

Ya hemos visto todos los tipos de repetición de un programa. Eso de cuando utilizarlos va depende del tipo del algoritmo que quieras utilizar. También es posible combinarlos para un código más grande. Pero OJO, no todos los tipos puedan funcionar. Hay que dejar claro los 3 tipos de repetición y con sus ejemplos debido a que ya se había explicado anteriormente en algunos WSQ y Masteries.

El uso de “while” se utiliza para que una operación se haga una y otra vez hasta que la condición se rompa. Un ejemplo sería el Método Babilónico. La variable “z” se rompe cuando este es igual a la variable “y”.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

El uso de “for” tiene muchos usos, pero lo principal es que establece ciertos límites y se hará la operación tantas veces hasta llegar a ese límite. Un ejemplo sería el de la Mastery 20 con el de las potencias. Se establece un límite en “b”, es decir, se hará “b” la misma operación.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

Y el uso de la recursión algorítmica  que se define la función a sí misma, es decir, se llama la función dentro de su misma función. El ejemplo sería el del Gran Común Divisor de la WSQ12. Dependiendo de los valores de “a” y “b”, se restará esos argumentos dependiendo de la condición llamando la función en sí.

MASTERY 22 When to use what type of repetition in a program

MASTERY 22 When to use what type of repetition in a program

#Mastery22 – When to use what type of repetition algorithms.

Here´s the link to a youtube video explaining when to use what type of repetition algorithms.

 

Click here.

 

1017

22

Mastery 22

When to use what type of repetition in a program

A repetition statement (or the looping statements or loops) enables the program to repeat an action as long as a particular set condition remains true. Its form goes as follow, “As long as you are at school, I will continue to pay your allowances”. This means that the action of paying you allowances will be done over and over again on condition that you go to school, but if you finish or drop out of school, you will have to fend for yourself. There are three types of repetition (loop) statements. They include the while,do.....while and for loop statements

while Repetition Statements

The while loop statements allows the program to perform a particular action while a set condition is true. In the case of our going to school example, the while statement can be stated as “while you go to school, I will pay your allowances”. Now this statement gives you the ability to determine how much you will earn while you go to school.
 

do..while statement

The do....while loop allows for executing an action at least before a condition is tested. To enable the loop automatically execute its statement at least once, the while condition is put at the end instead of the beginning. The loop executes its body before the condition is tested. So whether condition is true or false, the loop will execute at least once. 
 

for loop statement

The for loop is another form of repetition statements in C++. The for loop provides for the beginning of the condition, the limit of the condition and updates after every execution. The for loop takes the following form; for ( starting point; limiting condition; update ) { Code to execute while the condition is true }
The stating point can include an initialized control variable either declared internally or using an already existing variable. Any expression however that evaluates to a value can also be used. 
 
Credit:

1017 22

Mastery22

Repetitions

While: Is used for repeating sections of code until a defined condition is met.

For: Is used when you have a piece of code which you want to repeat n number of times. 

Recursion: Is when a function is called inside de same function.

It depends on what your program is about. While is used for repeting actions. For is used for actions that the function have to do for each element in something. And recursion is when you have some conditions that are going to change the original value and then it have to make the function again.

 

Link: https://github.com/LizethAcosta/Tareas/blob/master/Mastery22

22

 

Mastery 22

22 1017

En esta mastery esplicare los diferentes tipos de estructura de las funciones de ciclación.

entre estas estan

  • While
  • Do While 
  • For

empezaremos con while

Los while funcionan con el siguiente tipo de estructura, no se mantiene una condicion base y mientras se cumpla la condicion acordada en el while el programa seguira repitiendo su codigo hasta que no cumpla dicha condicion

Do while es muy similar al while pero tiene la diferencia que el codigo se tiene que cumplir una vez. 

en la imagen se muestra que el codigo bloque esta antes que la condicion dada lo que ocaciona que el ciclo se lleve acabo obligatoriamente una vez.

el tercer caso son los For

el For sigue una estructura diferente a las anteriores usando condicionales y un limite al que esta condicional puede llegar, mientras no se cumpla el limite seguira incrementando o decreciendo como el usuario haya estipulado.

#Mastery22 – #TC1017

22 1017

Two types of repetition structures: pretest and posttest loops

Pretest:

  1. Loop condition appears at beginning of pretest loop
  2. Determines number of times instructions w/in loop body are processed

  1. while
  2. for

  1. Loop condition appears at end of posttest loop
  2. Determines number of times instructions w/in loop body are processed
  3. HOWEVER, instructions processed at least once–the first time!

  1. do…while while

  1. the name of a control variable (or loop counter)
  2. the initial value of the control variable
  3. the loop-continuation condition that tests for the final value of the control variable to determine when to exit
  4. the control variable to be incremented (or decremented) each time through the loop

Using while Loop:

    • Executes from zero to many times, depending on expression
    • while is reserved word
    • Syntax of while statement:
while (expression)
  statement;
  • Expression provides entry condition
  • Expression (parentheses must be included as part of syntax) must evaluate to true to invoke loop statement(s)
  • Statement(s) can be simple or compound (block)
  • Statement(s) is/are body of loop
  • BE SURE to include an exit condition that will eventually evaluate expression to be false
  • Infinite loop: statement(s) continue(s) to execute endlessly
  • Loop invocation:
  1. Statement(s) execute(s) if expression evaluates to true
  2. Loop condition reevaluated
  3. Statement(s) continue(s) to execute until expression false
    • Executes a set number of times determined by the counter
    • Statement can be a single statement or a compound (block) statement.
    • for is reserved word
    • Simplifies writing of count-controlled while loop
    • Syntax of for statement (for loop control statements):
for (initial statement; test statement (loop condition); update statement)
     statement;

#Mastery22 #TC1017

When to use what type of repetition in a program

Para un programador es fundamental saber en qué momento es necesario usar los diferentes tipos de condiciones o de repeticiones, para ello les dejo un tutorial en donde se explcian las diferencias de repeticiones y el punto clave para saber qué tipo de repetición se debe utilizar: link del video abajo.

 

YOUTUBE:

 

http://youtu.be/kWtWraJtcJA?hd=1