do-while loop in C
do-while loop is place where the condition is to be tested.It will executes atleast one time even if the condition is false initially.In do-while,the condition is checked at the end of the loop.It executes until the condition becomes false.
Syntax:
do
{
//body of the loop.
}while(test-condition);
Lets take a simple program
A program to compute the factorial using do-while loop
A program to evaluate the series using do-while loop.
Difference between while and do-while loop
While Loop
|
Do-While Loop
|
Condition is specified at the top
|
Condition is specified at the bottom
|
Body Statements are executed when the condition is satisfied
|
Body Statements are executed when the condition is satisfied
|
No brackets for a single statement
|
Brackets are essential
|
It is an entry-controlled loop
|
It is an exit-controlled loop
|
No comments:
Post a Comment