PDA

View Full Version : nested loop in c



1991sudarshan
January 10th, 2010, 04:36 AM
could any one please explain me the mechanism of nested "for" loop inc language!!!!!

wmcbrine
January 10th, 2010, 04:47 AM
Eh? There's no mechanism... just one "for" loop inside another. If you know how to do a single "for" loop, then you can just as easily do nested loops.

Or did you really mean something besides "nested loop"?

1991sudarshan
January 10th, 2010, 04:53 AM
does the loop control get shifted form first loop to second loop and then back to first loop or else the second loop is executed completly and then goes to the first loop ???

Queue29
January 10th, 2010, 05:08 AM
does the loop control get shifted form first loop to second loop and then back to first loop or else the second loop is executed completly and then goes to the first loop ???

The inner for-loop will be initiated the number of times the outer for loop executes.

1991sudarshan
January 10th, 2010, 08:25 AM
thank you for the answer!!!!

dwhitney67
January 10th, 2010, 12:56 PM
thank you for the answer!!!!

Why did you elect *not* to write a test program?



#include <stdio.h>

int main()
{
int i, j;

for (i = 0; i < 5; ++i)
{
printf("i loop is executing...\n");

for (j = 0; j < 2; ++j)
{
printf("j loop is executing...\n");
}
}

return 0;
}

Are you fearful of doing basic research on your own?