Ticker

6/recent/ticker-posts

C Language (Do - While Loop)

DO WHILE LOOP

In the Do while loop, statements (body part instructions) executes first then it will check its test condition and if the condition turns out to be true then the statements are executed again.


A do while loop runs at least once even though the condition given is false.


int a=1;
do
{
printf(“\n%d”,a);
a=a+1;
}

while(a >10);

----------------------------
         OUTPUT 
----------------------------
1

Program Explanation: The above program will print 1 only, because the Do while loop execute at-least once even it test condition would be false.


PROGRAM TO PRINT REVERSE COUNTING 10-1 BY DO WHILE LOOP
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10;
do
{
printf(“\n%d”,a);
a=a+1;
}
while(a >=1);
getch();
}

----------------------------
         OUTPUT 
----------------------------
10
9
8
7
6
5
4
2
1












Post a Comment

0 Comments