C++ tutorial, C++ programs, C++ Exercises, C++ Example Programs

Tuesday, January 14, 2014

Explain Different Types of Iterative Looping Structures

What is a Looping Structure in C++?


A looping structure is a statement used to repeatedly execute a block of  one or more statements for a specified number of times or as long as a given condition remains true.

In C++, looping statements are also called Repetitive statements or Iterative Statements.

Different Types of  Looping Structures in C++


There are three types of looping structures in C and C++ programming languages, as follows:

  1. for loop
  2. while loop
  3. do while loop
Explain Different Types of Iterative Looping Structures
 Let us study these iterative statements deeply with syntax and purpose with the help of sample codes and outputs.

1. for Loop statement


A for loop statement is used to execute a block of one or more statements repeatedly for a specified number of times.

Syntax of for loop


for(initialization;condition;increment/decrement-expression)
{
    statement1;
    statement 2;
    .
    .
    .
   statement N;
}

Example of for loop


int d;
for(d=5; d>=1; d--)
   cout<<d<<endl;

Output:

5
4
3
2
1

2. while Loop Statement in C / C++


while loop is used to execute a block of one or more statements repeatedly as long as the given condition remains true.

Syntax of while loop


while(condition)
{
    statement1;
    statement 2;
    .
    .
    .
   statement N;
}

Example of while loop


int f=5;
while(f>=1)
{
    cout<<f<<endl;
    f--;
}

Output:

5
4
3
2
1

3. do while Loop statement in C / C++


A do while loop is used to execute a block of one or more statements as long as the given condition remains true but condition is placed after loop body.

Syntax of do while loop


do
{
    statement1;
    statement 2;
    .
    .
    .
   statement N;
}
while(condition);

Example of do while loop


int h=5;
do
{
    cout<<h<<endl;
    h--;
}
while(h>=1);

Output:


5
4
3
2
1http://easycppprogramming.blogspot.com/2014/01/working-of-for-loop-statement-with.html

After studying a brief description of Different Types of Iterative Looping Structures in C++
For further reading:


Purpose and Example of do while Loop in CPP Language
Working of for loop statement with examples

Working of While Loop With Examples
Share:

0 comments:

Post a Comment

We Love To Hear From You!

EasyCPPprogramming.blogspotcom

Labels