Description

Loops in c programming 

What is loops?

A control sturcture that repeats a group of steps in a program is called a loop. When we want to same piece of code execute many time then we used the loops. Loops is used for in programming for repetition ( to repeat the same piece of code in program ).

Types of Loops

  1. For loop
  2. while loop
  3. do while loop

For Loop : The for loop is used when we want to execute the code until the given condition is true(satisfied), When the programmer knows how many times a set of statements are to be executed.

Syntax of for loop

for(/*initilization*/; /* condition */ ; /* increament or decreament */)
{
    // code here
}

while loop : This loop is used to execute the set of instruction repeatedly as long as the specified condition is true ( satisfied ). This loop is also called pre-tested loop.

The means of pre-tested loop is this loop is check the condition first and the condition is true then execute the statement.

Syntax of while loop

while(/* condition */){
    // code here
}

do while loop : The do-while loop continues until a given condition satisfies execute the code. This loop is also called the post-tested loop. The means of post-tested loop is this loop is execute the statement first and check the condition is after.

Syntax of do while loop

do{
    // code here
}while(/* condition */);

Advantages of loops in c 

  1. It provides code reusability.
  2. Using loops, we do not need to write the same code again and again.
  3. Using loops, we can traverse over the elements of data structures.

 

Please do Comment and give your suggestion in the comment box.

Comments

Login is mandatory to comment Please login

Recommended Posts

Array in c programming language

An Array is the list of finite number of elements of same data types. For Example: interger, string, float etc. An Array can be defined as the collection of the

Break and Continue Statement in c

Break statement is usually used to terminate a case in the switch statement. In c programming language the continue statement works...

Function in C | What is Functions?

Function like main(), printf() and scanf(), we have already come through. All c Programs made up of one or more function.