Thursday, October 11, 2018

Repetition

Repetition Definition


· One or more instruction repeated for certain 

amount of time

· Number of repetition can be predefined (hard-

coded in program) or defined later at run time



How to use Repetitions ?


In the C Progamming language, there are 3 types of looping/

repetition operations  . Each of them has different functions



. For Loops iterates until a condition is met

. While Loops repeats until a condition is met

. Do-While Loops runs and then checks the condition


Repetition examples : 

FOR

- Program to print out numbers from 1 to 10


#include<stdio.h>

int main()

{
    int x;

    for( x = 1 ;  x <= 10 ;  x++

    printf("%d\n", x );

    return(0);
}


Repetition examples : 

WHILE


int counter = 1;

while ( counter <= 10 ) {

     printf( "%d\n", counter );

     ++counter;
}

Repetition examples : 

DO-WHILE


int counter=0;

do {
     printf( "%d  ", counter );

  ++counter;

} while (counter <= 10);



Why we use Repetitions ?


. Less redundant code

. Efficient and Effective to 

solve problems

. Minimize effort of coding


When to use Repetitions ?

. Less Time Coding

. More Time Thinking