for loop problem :(

Topics regarding Scripting with Reality Factory
Post Reply
Juryiel
Posts: 103
Joined: Fri Jan 04, 2008 1:18 pm

for loop problem :(

Post 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!
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps »

i thought you might need a break statement, but isnt that in switch statements?
1 wrote:
for the internet is a cruel and dark place at times, and there's sex and blood everywhere.

2 wrote:
You say that like it's a bad thing.

1 wrote:
You are a bad thing.
Juryiel
Posts: 103
Joined: Fri Jan 04, 2008 1:18 pm

Post 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 :)
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps »

Im glad you found a different solution. :)
1 wrote:
for the internet is a cruel and dark place at times, and there's sex and blood everywhere.

2 wrote:
You say that like it's a bad thing.

1 wrote:
You are a bad thing.
Post Reply