Wednesday, 18 January 2012

Program Of Do While Loop In C++


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int i;
i=3;
do
{
cout<<"\n"<<i;
 i+=2;
}
while(i<100);
getch();
}

------------------------------------------------------------------------------


The do-while loop is similar to the while loop, except that the test condition occurs at the end of the loop. Having the test condition at the end, guarantees that the body of the loop always executes at least one time. The format of the do-while loop is shown in the box at the right.

The test condition must be enclosed in parentheses andFOLLOWED BY A SEMI-COLON. Semi-colons also follow each of the statements within the block. The body of the loop (the block of code) is enclosed in braces and indented for readability.
The do-while loop is an exit-condition loop. This means that the body of the loop is always executed first. Then, the test condition is evaluated. If the test condition is TRUE, the program executes the body of the loop again. If the test condition is FALSE, the loop terminates and program execution continues with the statement following the while.

No comments:

Post a Comment