Semester : S1 and S2
Subject : Computer Programming
Year : 2017
Term : DECEMBER
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:13
do while
On some occasions it might be necessary to execute the body of the loop before test is performed. Such situations
can be handled with the help of do while statement. General form: do
{
Body of the loop
} while (test condition);
On reaching the do statement the program proceeds to evaluate the body of the loop first. At the end of loop, the
test condition in the while statement is evaluated. If the condition is true, the program continues to evaluate the
body of loop once again. This program continues as long as the condition is true. When the condition becomes false,
the loop while be terminated and the control goes to the statement that appears immediately after while statement.
Since, the test condition is evaluated at the bottom of the loop,the do while construct provides an exit-controlled
loop and the form the body of the loop is always executed at least once. Flow chart for exit control:
entry
| അയ: | of the loop
Test ணை سم
வட. மரியா.
ஷ் பன்
Out put
Example: To print ‘n’ natural number using do while
#include < stdio.h>
#include > conio.h>
void main()
{
int n,i=1;
clrscr();
printf("enter any number");
scanf("%d" ,&n);
printf("natural numbers from 1 to %d",n);
do