Page 1 of 1

for loop problem :(

Posted: Wed Jan 16, 2008 7:49 am
by Juryiel
So I have the following loop

Code: Select all

for i = startRange+(2*numEntriesPerItem) to 200 step 2*numEntriesPerItem
			{
				i=Integer(i);
				if(((Integer(Item_Array[i+5]) = Integer(currMenuSubCategory)) or (Integer(Item_Array[i+5+numEntriesPerItem]) = Integer(currMenuSubCategory)) or (Integer(currMenuSubCategory)=0)) and ((Item_Array[i+1] > 0) or (Item_Array[i+numEntriesPerItem+1] > 0)))
				{
					setRange=i;
					//debug(setRange);
					//i=Integer((Item_Array.numChildren+1)-numEntriesPerItem)+1;
					
					debug(i);
				}
				i=i+476;
			}
Theoretically this loop should only run once and then exit since the line i=i+476 is there. However, it runs all the way up to 200 in increments of the step value without exiting until the end. It seems that maybe the i=i+476 line is being ignored, but more likely, I'm doing something stupid like missing a parentheses somewhere :) Help if you can!

Posted: Wed Jan 16, 2008 2:09 pm
by fps
i thought you might need a break statement, but isnt that in switch statements?

Posted: Wed Jan 16, 2008 3:06 pm
by Juryiel
Apparently break statements aren't in until next version. But I would think if I set i to some huge number it should meet the condition to break the loop. Oh well I just converted the logic to a while loop and it works like a charm :)

Posted: Wed Jan 16, 2008 4:09 pm
by fps
Im glad you found a different solution. :)