for loops help...
Sep 18, 2014 at 11:08am UTC
I want to create a specific number of for loops each in another loop, as in example:
1 2 3 4 5 6 7 8 9 10
for (i=0;i<9;i++)
{
for (j=0;j<9;j++)
{
for (k=0;k<9;k++)
{
//some stuff
}
}
}
In this example there are 3 loops, but what if i want to create e.g. 10 such loops, and program reads a number of loops from a txt?
It is needed for checking numbers.
Sep 18, 2014 at 11:29am UTC
Rough example:
1 2 3 4 5 6 7 8 9 10
void do_nested_for(int iterations, int level)
{
if (level > 1)
for (int i = 0; i < iterations; ++i)
do_nested_for(iterations, level - 1);
else
for (int i = 0; i < iterations; ++i) {
//some stuff
}
}
Sep 18, 2014 at 1:03pm UTC
Cool! thanks!
Topic archived. No new replies allowed.