Monday, March 7, 2016

Working Of while loop

 The while loop operates as follows , the condition is tested ,if the it is true .
That is the condition is true that means

for example
            10 == 10 . or 10<20 .="" etc="" p="">If it is true the statement in the while loop will be work or execute 


while(i < j )
{
  stament for exection

}



Example
 
   while(far <= upper )

     {  

       celsius = 5 * (far - 32)/9;

       printf("%d\t%d\n", far ,celsius);

       far += step;

  }


it will execute till until the condition will get false  .

that is the far not equal to upper 


NB : 

   The body of the while loop may be single or more line .
  If there is a single line there is no need to add a the curly {} bracket 

Eg : 
       while(i < j)
        i = 2 * i ;  // it will repeat until the condition fall 



No comments:

Post a Comment