I have the following two loops for sequence. It is very strange that the first for loop works when I run it alone. But when I run the second loop alone, I get an exception error out of range. Can someone help me check what the error is? Thank you very much!
for (i = NiPricePointer; i < 551; i++) { tempUpper = tempUpper + NiPriceCounter[i]; if (tempUpper >= (NiPriceRounds * 0.3)) { chart3.Series["Upper 30%"].Points.AddXY(k * 500, ((i - 1) * 0.1 + 5)); break; } } for (i = NiPricePointer; i>0; i--) //This loop always gives me out of range problems. { tempLower = tempLower + NiPriceCounter[i]; if (tempLower >= (NiPriceRounds * 0.3)) { chart3.Series["Lower 30%"].Points.AddXY(k * 500, ((i - 1) * 0.1 + 5)); break; } }
Array initialization:
int[] NiPriceCounter = new int[551];
Thanks a lot!
source share