Thursday, January 20, 2011

9.do-while Loop Statement


do while loop statement allows you to execute code block in loop body at least one. Here is do while loop syntax:

1do {
2  // statements
3while (expression);
Here is an example of using do while loop statement:
01#include <stdio.h>
02void main(){
03    int x = 5;
04    int i = 0;
05    // using do while loop statement
06    do{
07        i++;
08        printf("%d\n",i);
09    }while(i < x);
10  
11}
The program above print exactly 5 times as indicated in do while loop body
1
2
3
4
5

Dont Miss Another Post Connect With Us !

Enter your email address:

0 comments: