Nesting of loops in C++

by Nideesh C on May 7, 2011 · 0 comments

in C++




When a loop is written inside other loop, then the representation is know as the nesting of looping constructs. In this representation,the child loop is executed fully and then the control is transferred to its parent loop for the next repetition.

Nesting of loops

Example program:

#include<iostream.h>

#include<conio.h>

void main()

{

char ans=’y';

int x=1,y;

while(ans!=’n'||ans!=’N')

{

count<<”Enter repetions :”;

cin>>y;

while(x<=y)

{

cout<<x<<endl;

x++;

}

x=1;

cout<<endl<<”Continue (y/n) ?;

cin>>ans;

}

}

Output:

Enter repetitions :2

1

2

Continue (y/n) ? y

Enter repetitions :4

1

2

3

4

Continue (y/n) ? y

Enter repetitions :1

1

Continue (y/n) ? n

See also: For loop in C++

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. For loop in C++
  2. Java program – Nested loops
  3. While loop in C++
  4. How to add widgets to wordpress footer ? Step by step simple tutorial
  5. Do…while loop in C++

Leave a Comment

Previous post:

Next post: