I want to write a code which has unknown number of loops:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int x[n];
for(int i=0; i<10; i++) {
x[0] = i+1;
for(int j=0; j<10; j++)
x[1] = j+1;
for(int k=0; k<10; k++)
x[2] = k+1;
.............
upto n loops
do something with x[n]
}
}
}
Because n is unknown at the compilation time and it could be large (> 10), I want to write these loops in some compact form. Any idea how to write all these loops in compact form?
int Function(int Limit, int Increment)
{
for(int i = 0; i < Limit; i = i + Increament)
{
//Code Code Code Call This Function From Some Where In Here
}
return something;
}
In general, when you don't know the number of times a loop is goint to be executed, you have to use: do {single loop} while (condition);
or while (condition) {single loop}