Nested loop in c++ with example

c allows for, while and do while loops to be nested. that is one loop is inside another loop.

Example:-


Output:-

.....
....
...
..
.

one type of loop can be nested with other type of loop. for example while loop is inside for loop.

Example:-



Previous Code:-
Do while loop

List Code:-
C++ Codes

Next Code:-
Switch case

C++ Programs
List of c++ Programs

10 Comments

  1. What are loops and how we can use them?

    In general a loop is a sequence of statements which is specified once but which may be carried out several times in succession. The function of the loop is to repeat the calculation a given number of times until it reaches a certain value. The code inside the loop is obeyed a specified number of times, or once for each of a collection of items, or until some condition is met, or indefinitely. We can divide loops into:
    1) Count-controlled loops,
    2) Condition – controlled loops,
    3) Collection - controlled loops,
    4) General iteration,
    5) Infinite loops,
    6) Continuation with the next iteration,
    7) Redo the current interation and
    8) Restart loop

    For more information please visit: http://megacplusplustutorials.blogspot.com

    ReplyDelete
  2. The output of first question is wrong.. it should be like this -->

    ......
    .....
    ....
    ...
    ..
    .

    ReplyDelete
  3. . Write a program that uses nested loops to display the following lines.

    1 2 4 6
    2 2 4 6
    3 2 4 6
    4 2 4 6
    5 2 4 6


    ReplyDelete
  4. question
    11
    21 22
    31 32 33
    41 42 42 44
    pleassolve it

    ReplyDelete
    Replies
    1. // C++ program to add numbers until user enters 0

      #include
      using namespace std;

      int main()
      {
      int j, i ;
      for (i= 1 ; i <= 4 ; i++){
      for ( j=1 ; j <=i ; j++ ){
      cout << i << j <<" " ; }
      cout << "\n";
      }

      return 0;
      }

      Delete
  5. pleas help me to c++

    A.
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5

    B.
    1 1 1 1 1
    2 2 2 2 2
    3 3 3 3 3

    C.
    1 1 1 1 1
    2 2 2 2
    3 3 3
    4 4
    5

    A.
    1 2 3 4 5
    6 7 8 9
    10 11 12
    13 14
    15

    ReplyDelete
  6. please help in c++
    input number = n
    ex.n =5
    output
    1+2+3+4+5=15

    ReplyDelete

Add your comments here

Back to Top