Code: for ( i = 1 ; i < BarCount ; i++ ) { while ( C[i] > O[i] ) { upbar = upbar + 1 ; } } Where is the endless loop? It says it's an endless loop, but I just don't see it. Thanks.
Everytime the condition within the while loop is true, it stays in the while loop, repeating ub=ub+1; It's unable to exit the while loop until the condition becomes false. Only way it will become false is to increment i to i=i+1, which skews the for loop index. You could try a different index within the while loop, set it equal to i, then increment your new index to index=index+1; This will enable the while loop to eventually find a condition that's false. Logically, there's no reason for the while loop to be combined with a for loop. You should use one or the other. I prefer the for loop because you can say if whatever[ i ] then ub=ub+1; // and it will automatically increment i or you could use i=1; while (i<barcount) { if (c[ i ] > O [ i ]) {ub=ub+1} i=i+1; } Another factor to consider, double check to make certain uppercase O is not the numeral zero.
Most of the endless loop errors occur in while loops. They hardly ever occur in for loops. If there's a reason to stop at an address like i, and check for some condition over more than a single bar, then you can nest a 2nd for loop inside the 1st for loop, by assigning the val of the 1st index to the 2nd index, and using a different letter for the 2nd index. It's easier to do in practice than to describe in theory.
Why indeed. Thanks, finally "finished." This stupid thing was giving me a headache. Code: upbars = IIf ( C != O , Sum ( C > O , BarsSince ( O > C ) ) , 0 ) ; downbars = IIf ( C != O , Sum ( O > C , BarsSince ( C > O ) ) , 0 ) ;