Loops in C - What is while loop in c - Syntax and Example of while loop in c

Control Statement  

Generally C program statement is executed in a order in which they appear in the program. But sometimes we use decision making condition for execution only a part of program, that is called control statement. Control statement defined how the control is transferred from one part to the other part of the program. There are several control statement like if...else, switch, while, do....while, for loop, break, continue, goto etc.


Loops in C

Loop:-it is a block of statement that performs set of instructions. 

In loops Repeating particular portion of the program either a specified number of time or until a particular no of condition is being satisfied.

There are three types of loops in c 

1.While loop 

2.do while loop 

3.for loop 

While loop

The test condition may be any expression .when we want to do something a fixed no of times but not known about the number of iteration, in a program then while loop is used. 

Here first condition is checked if, it is true body of the loop is executed else, If condition is false control will be come out of loop.

Syntax




Example




Output: 

Welcome to C 
Welcome to C  
Welcome to C 
Welcome to C 
Welcome to C

So as long as condition remains true statements within the body of while loop will get executed repeatedly. 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.