Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , , , ,

Sponsored Links



What does nested loops means?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 27-11-2009
Zhankana_n's Avatar
Member
 
Join Date: Nov 2009
Posts: 1,429
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..
Reply With Quote
  #2  
Old 27-11-2009
Member
 
Join Date: May 2008
Posts: 1,990
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:
Quote:

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...
Reply With Quote
  #3  
Old 27-11-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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:

Quote:
#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;
}
Reply With Quote
  #4  
Old 27-11-2009
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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.
Reply With Quote
  #5  
Old 27-11-2009
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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:
Quote:
#include

void main ( )

{

int a, b;

clrscr ( );

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

{

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

{

printf (“#”)

}


}

getch ( );

}
Reply With Quote
  #6  
Old 27-11-2009
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: What does nested loops means?

Hi Friend,

Below is the syntax for the Nested loops:

Nested loops syntax :-

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

{

//body of loop

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

{

loop body;

}

}
hopefully It will helps you...
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What does nested loops means?"
Thread Thread Starter Forum Replies Last Post
How to run Nested Vms Vitel Operating Systems 8 15-09-2011 12:54 PM
What is Nested Class in C++? Allman Software Development 4 02-01-2011 01:32 AM
Nested groups ThePro Active Directory 4 12-02-2010 09:41 PM
How to create While Loops in PHP? MarceloQuad Software Development 5 28-01-2010 09:04 PM
I want a CD of 'Inner Loops' Solaris Portable Devices 5 09-07-2009 05:35 AM


All times are GMT +5.5. The time now is 11:28 AM.