Results 1 to 6 of 6

Thread: What does nested loops means?

  1. #1
    Join Date
    Nov 2009
    Posts
    1,416

    What does nested loops means?

    Hi Friends,

    I just stated C programming. I was not quit difficult to understand the concept of looping. But when nested looping concept started , It's too difficult for me to understand.]

    I am not getting what does nested loops exactly means. Is nested loop is any new type of loop? or what.

    Pleas help me to understand the concept of nested loops..

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: What does nested loops means?

    Hi Friend,

    Your confusion is valid , because it was also too difficult for me to understand the nested looping.

    When we use a loop inside another loop then it is referred as nested loop.
    Refer the following program in which I used "For loop" inside another "For loop":

    Example of loop nesting:

    for(a=0; a<=15; a++)
    {
    for(b=0; b<=20; b++)
    {
    printf(a,b);

    }
    }

    I hope it will definitely help you to understand nesting of loops...

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What does nested loops means?

    Hi,

    I have C language program which will demonstrate you the concept of the nested loops. Nesting simply means loop within loop. Nested loops helpful in the program in which we have to test multiple complex conditions .

    Please go through below program:

    #include <stdio.h>

    int main(void)
    {
    int ans, x, ch, correct;

    for(x= 1; x< 11; x++) {
    printf(" %d + %d = ?", x, x);
    scanf("%d", &ans);

    if(answer == x+ x)
    printf("correct!\n");
    else {
    printf("Wrong.\n");
    printf("Try again.\n");

    right = 0;
    // nested for loop
    for(ch = 0; ch < 3 && !correct; ch++) {
    printf(" %d + %d = ? ", i, i);
    scanf("%d", &ans);

    if(answer == i + i) {
    printf("correct!\n");
    correct= 1;
    }
    }

    if(!correct)
    printf("answer = %d.\n", i + i);
    }
    }

    return 0;
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: What does nested loops means?

    Hi friend,

    I don't have sound knowledge about the nested loops, But below are the some points which will help you to understand the concept of the nested loops :

    1. The process of using loop inside the another loop is known as "nested loop".

    2. Nested loops used when you want to run multiple conditions at the same time.

    3. The inner loop will execute only when the outer loop condition is true.

    4. If the condition of the outer loop is false then the program won't execute the inner loop.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What does nested loops means?

    Hi All,

    *. Nested loops comprises statement of another looping within single loop. Usually nested loops are useful while creating the "matrix".

    *. I hope you aware that loop can include any number of statement of the loops in it. If you use any "Loop" inside other "Loop" is known as loop nesting.

    *. Mostly loop of the inner side is used to for row counting, While outer is for column counting.

    Please go through below example:

    Example:
    #include

    void main ( )

    {

    int a, b;

    clrscr ( );

    for (b=1; b<=4; b++)

    {

    for (a=1; a<=5; a++)

    {

    printf (“#”)

    }


    }

    getch ( );

    }

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: What does nested loops means?

    Hi Friend,

    Below is the syntax for the Nested loops:

    Nested loops syntax :-

    for (initialization ; condition to test; decrement/increment )

    {

    //body of loop

    for (initialization ; condition to test; decrement/increment)

    {

    loop body;

    }

    }
    hopefully It will helps you...

Similar Threads

  1. How to run Nested Vms
    By Vitel in forum Operating Systems
    Replies: 8
    Last Post: 15-09-2011, 11:54 AM
  2. What is Nested Class in C++?
    By Allman in forum Software Development
    Replies: 4
    Last Post: 02-01-2011, 01:32 AM
  3. Problem of nested query
    By MAGAR in forum Software Development
    Replies: 4
    Last Post: 09-12-2009, 09:55 PM
  4. Problem in Nested folder in .NET
    By rashmi_ay in forum Software Development
    Replies: 3
    Last Post: 30-11-2009, 10:36 PM
  5. I want a CD of 'Inner Loops'
    By Solaris in forum Portable Devices
    Replies: 5
    Last Post: 09-07-2009, 04:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,058,597.64481 seconds with 16 queries