Friday, 15 February 2013

for and while

break and continue
These interrupt normal flow of control
break causes an exit from the innermost enclosing loop
continue causes the current iteration of a loop to stop and the next iteration to begin immediately

do-while
§When a loop is constructed using

 while, the test for continuation is


 carried out at the beginning of each


 pass
§With do-while the test for continuation

 takes place at the end of each pass
  
do
  {
    statement

  } while (expression);



Example

int i = 1, sum = 0;

  do

  {

  sum = sum + i;

            i= i + 1;

  }while(i<=10);

  printf(“Sum = %d\n”, sum);


while  vs. do-while

§while -- the expression is tested first, if 

the result is false, the loop body is never 


executed

§do-while -- the loop body is always

 executed once. After that, the 
expression is tested, 

      if the result is false, the loop  body is not executed 

     again.






No comments:

Post a Comment

String functions

Read This: strncpy() strncat() strstr () strlen() — Predefined function defined in string.h . — — Returns the len...