Feed Headline Animator

What are loop and its types

Loop: -

A cycle process to called loop. Or if some kind of task is required more then one times then we use loop.

Types of loop: -

In C language there are three types of loop.

(1) For loop (2) While loop (3) Do-while loop

(1) For loop: -

If the number of cycles or repetition is already known then we use for loop.
Its syntax is:
For (variable = initial value; condition; increment or decrement ;)
{
Body of loop
}

So in the above structure first of all the value is initialized in the given variable, then in the second part that value is checked in the given condition, it is prove that body will process and if it is will become false then body of loop will not process in the tired part the value in variable is increment or decrement and then it is again checked in the condition part.

(2) While loop: -

The numbers of cycles or repetitions or iterations are already not known then we use while loop.
The syntax is:
While (condition)
{
Body of loop
}
So in this loop, first of all condition is checked, if it remains true the body of loop will process otherwise it will be stopped.

(3) Do-while loop: -

It is also a conditional loop like while loop, but in this loop condition is checked in the end, where as in the whole loop condition is checked first.
Its syntax will be as:
Do
{
Body of loop
}
While (condition);
So in this loop the body of loop will be processed one time at any case, whether the condition is true or false.


Posted by: Wasim Javed

No comments:

Post a Comment