Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

Looping in #C : Do-while loops and their uses in programs (module 22)

In this section we will learn on the topic and concepts of loops, it's uses in programs. Types of loops, while loops, do-while loops, for loops etc

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
This is the 22nd module on learning C with us. Earlier we discussed on the basic introduction and structure of C, preprocessor it's features, intermediate and executable codes. compilation and execution process of a C program. And keywords and identifiers, data types, variables and constants, scope of variables, operators and expressions in C. Type casting in #C. Introduction to input and output functions and reading a character in #C. Unformatted and formatted input functions. Branching statements like if, if-else, nested if-else. 
In this section we will learn on the topic and concepts of loops, it's uses in programs. Types of loops, while loops, do-while loops, for loops etc.
Do-while loops :-

Format :
Do {
Statements 
} while (condition)
In do-while loops the loop is compulsory executed one time.
In Do-while loop statements inside the block are executed for the first iteration and then test the given condition at the ending of the block, if the condition is tue then the statements in the loop are executed, if the condition is false then the statements after the block are executed.
This is called as exit controlled loop.

Example :
 int main()
 { int i,c,a;
  char ch;
 do{
 printf("1. f to c\n");
 printf("2. c to f\n");
 printf("enter your choice\n");
 scanf("%d",&c);
 if (c==1)
 {
 printf("enter the value of f\n");
 scanf("%d",&i);
 a=((i-32)*5)/9;
 printf("temp in c=%d\n",a);
 }
 else if (c==2)
 {
 printf("enter the value of c\n");
 scanf("%d",&i);
 a=((9*i)/5)+32;
 printf("temp in f=%d\n",a);
 }
 else
 { printf("INVALID ENTRY\n"); }
 printf("Do you want to continue ?(y or n)\n");
 fflush(stdin);
 ch= getch();
 }while (ch=='y'||ch=='Y');
 return 0;
 } 
In next module we will continue our discussions on the next topic on loops like for loop. For more information regarding #C please be updated with us only on Www.newsandstory.com as we provide all the information on all the topics covered in #C.
CONTINUE READING
loops
do-while
while
entry control
exit control
statements
concepts
technology
programming
learning
coding
#C
Dalpat I
Content writer