Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Do-while Loop in C programming

August 25, 2013 Posted by: GPA Views: 632 0 comments

In this lesson you will see how you can use the do-while in C.
Sometimes there is a need to perform loop body at least once, even if the boolean expression evaluates to the beginning false. For such cases, C has the loop structure do-while. Its general form of this:

do {

   body;

   [iteration;] 

} while (end); 

In the following example, the loop body is executed before the condition check. This program will show numbers from 0 to 9 and break when counter equal 9.

  

#include <stdio.h>
#include <stdlib.h>
//main function
int main(int argc, char *argv[]){
    int counter=0;//counter
    do{
       printf("%d\n",counter);
       counter++;
}while(counter<10);//end do while loop
system("PAUSE");//delay  
return 0;
}

Output

Do-while Loop in C example

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe