< Prev
Next >



Do-While Loop





In do-while loop of C language, a block of statements or the body of loop always comes before the condition of do-while loop is tested.







do while loop example


/* do-while example */
 
#include<stdio.h>
int main()  /* main method starts */
{
int i=0;

do 
{
	
	printf("i = %d \n",i);
	i++;

}while(i<5);

return 0;
}


Output


i = 0
i = 1
i = 2
i = 3
i = 4





do while loop is executed at least once


The body of do while loop is always executed during its first execution, even when the condition of loop is evaluated to be false, take a look at our next example -
/* do-while second example */
 
#include<stdio.h>

int main()  /* main method starts */
{
int i=100;

do 
{
	
	printf("i = %d \n", i);
	i++;

}while(i<10);

return 0;
} /* main method ends and so does the program */


Output


i = 100




Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter




< Prev
Next >
< For Loop
While Loop>
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
Python

Ad2