This blog is under construction

Saturday 21 April 2012

Loop control structure - do while statement

do while is a loop construct which executes the statements inside the loop at least once, regardless of whether the expression is true or false.  If the expression evaluates to be false, then the loop terminates.  Otherwise, the statements inside the loop will get executed.  This continues until the expression evaluates to be false.  Below is the syntax for do while loop construct.

Syntax for do while loop construct:
do {
statements;
} while(expression);


Example C program using do-while:
 
  #include <stdio.h>
  int main() {
        int i = 1;
        do {
                printf("%d\n", i);  // print the value of i
                i++; // incrementing the value of i
        } while(i < 10);  // validating the expression
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  1
  2
  3
  4
  5
  6
  7
  8
  9



1 comment:

  1. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete