Our Blog Contain Detail about Some Technical Aspect like Programming, Blogger, Tools and Tip, Suggestion, Motivational, Health, Program in C and Java, Html

List the various types of loop available in C and explain any one with the syntax and suitable example.

 List the various types of loop available in C and explain any one with the syntax and suitable example.



Index

1. What is Loop

2. Various Type of Loop

3. Example of Loop

Ans: 

What is Loop

Loops:-Loops are the statement used to execute a sequence of instruction repeatedly. 

Various Type of Loop

There are three types of loop statements in C:
1.    for loop
2.    while loop
3.    do while loop

 

(1)    for loop:- for loop is used to execute statement multiple times .

            Syntax of for loop:-

            for(initialization ; condition ; increment/decrement){

                                    //body of loop

                        }

 

            Example:-

#include <stdio.h>

int main()

{

for(    int i = 5; i<10;i++)

 {

printf("%d\n",i);

    }

    return 0;

}

 

           

(2)    while loop:-The while loop is a control flow statement which is used to execute the statement repeatedly till the condition statement is true.

 

Syntax for while loop:-

while (boolean condition)

{

   loop statements...

}

 

Example:-

#include <stdio.h>

int main()

{

    int i = 5;

      while (i< 10) {

printf("%d\n",i);

i++;

    }

    return 0;

}

 

(3)    do-while:- Do while loop is similar to while loop with a difference that do-while loop execute the state then after that is check the condition.

Syntax for do-while loop:-

do

{

    statements..

}

while (condition);

 

Example:-

#include <stdio.h>

int main()

{

    int i = 5;

      do {

printf("%d\n",i);

i++;

    } while (i< 10)

    return 0;

}

Share:

No comments:

Post a Comment

Translate

Followers

Email Subscription

Enter your email address:

Delivered by FeedBurner

Recent Posts

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.