Posted By:
11 Jun, 2013 12:14 am PDT

Loops in C and C++

What are the loops used in c programming? give examples

A loop statement allows us to execute a statement or group of statements multiple times and there are three loops

  1. While
  2. Do while
  3. For


Please watch the video for details....

Was it useful?  

The following are the conditional loops for C and C++.


For Loop

First comes the "for (;;;)" loop.

// code/s to be executed; 

The first part is to initialise the variable.

After initializing the variable , the control of program goes to the second part- Condition. If the value of variable is satisfying the condition then the control enters the loop.

After executing the statements inside the loop , the control is then transferred to the third part , Increment/Decrement.

Then again this loop continues till the Condition is satisfied.


While Loop

The next type of loop is the " While " loop.

Syntax is:

while (condition)
// statements to be executed. 


This means that , as long as the condition is satisfied , the loop is executed.



Do-While Loop

The next loop is "do..While" loop.

The syntax is :

// some code/s;
while (Condition);


This means that , first the code is executed and then the condition is checked . If the condition is not satisfied , the control exits the loop,but the loop is executed at least once.


Was it useful?  

Please login to reply to this problem.