Pages

Looping & Branching Statement

Loop are very important in any  Programing  language.Looping is used when we execute the statement in multi time .The part which is executed again and again in this manner is know as the body of the loop. During the execution of the loop  whenever the control falls to the end of the body of loop .it again jumps to the starting point of the body of the loop  This is continues as long as some predefined condition is satisfied .They are three type

1  While Loop
2  Do While Loop
3 For Loop

 while Loop  This is used to execute the block of statements till the value of the conditional expression is true .While loop if is true then the body of the loop is executed .After  execution of the body (contain statements and  increment /decrement par) the test condition is again tested and if it is true then  the body is executed again .
Syntax :
 while(expression)
{
statement 1;
increment /Decrement ;
}

                                           

do while  it can execute the statement first and check the condition after . statement will execute  once even if the  expression  is false .condition is checked at the end  of the do while loop.
Syntax

                 do
               {
                 statement ;
                increment/decrement;
                    }
         while (condition);

                                       


for loop  for loop is used to initialize ,testing and increment/decrement into single line .this is fast and simple loop .
Syntax .for (variable initialize;testing;increment /decrement)

                                       
                                        

Nested Loop  Nested Loop inside the another  loop..
Syntax
              for (variable initialize;testing;increment /decrement)

             {
             for (variable initialize;testing;increment /decrement)

              {
                      statements;
               }
               }


Branching Statement   There are many  other control  statements that can change the execution of loop or execution of the programe .These are given below

break  ---these are used to exit from  the loop or exit from the switch case 

continue--the continue statement is used to skip  the remaining statement of the body of the loop.it does not terminate the loop but transfer the control to start of the next  loop iteration.

goto   .it can jump the control to desier location




0 comments: