Would anybody explain me, please, why is the method executed only on iterations of the first loop and the second one modify only the end2 variable but the method isn’t called!!!
I hope my explanation of the problem is clear enough.
OK I found something through debugging! The problem isn’t as I describe it, the loops work correct and the method wrong!
Thank you for your advices I appreciate your help
int[] array = {7,3,5,4,9,1,3,2,5};
for (int i = 1; i < array.Length; i *= 2)
{
for (int j = 0; j < array.Length - i; j += 2*i)
{
end2 = (2 * j < array.Length - i) ? (2 * i) : (array.Length - j);
Method(j, i, end2, array);
}
}
Thank you
BR
Stephan
Im not sure if I understand your question correctly, but if you use nested loops, then in your case the outer loop is executed once with i = 1. This means the inner loop is executed with j= 0 until j receives the limit j < array.Length – 1.
Then the outer loop again is executed with i = 2. That means the inner loop is sexecuted with j = 0 until j receives the limit j < array.Length – 2;
This continues until the outer loop reaches its limit.