10 Oktober 2018 - Repetition


Topic : Program Control : Repetition

Sub-topic : 
  • Repetition Definition 
  • For 
  • While
  • Do-While 
  • Break vs Continue 
A. Repetition Defenision
     Repetition is an action that repeating the same thing.
     in C we can use some operation to make repetition or looping such as:
  • for 
  • while
  • do-while
B. For
     syntax : for(initialization; condition; after-statement) statement;
                   or:
                  for(initialization; condition; after-statement) {
  statement1;
  statement2;
  ……. }
     example : for (i=0;i<n;i++) printf("hi");

C. While
     Syntax : while (condition) statements;
                   or:
                   while(condition){
            statement1;
            statement2;
                    …..}
      example : while(n>1) n--;

D.  Do-While
      Syntax : do{
                          < statements >;
                        } while(condition);
      Example : do { printf("%d",i); i++}
                        while (i<=9);

     different between While and Do-While is if the condition false, while will never be run but do             while run atleast once.

E.  Break Vs Continue
  • Break used for Force Stop looping or repetition.
  • Continue used for skip the rest of the statement and continue to the next loop

Nama : Meichel Rendio
Nim : 2201749305
Binus.ac.id
skyconnectiva.com








Comments