General

question for loops (i iterations)

Started by Softcore on .

Sign in or create an account to join the conversation.

5 posts

Topic starter
I hope you can enlighten me....

Is it "ok" to use a for i loop and not use i inside the loop (just use it as a counter).....for example lets say I have 30 objects to turn off...(x=0)
Is it ok to go:
decl i,obj=Knob1;
for (i=0; i<30; i++)
{
setexpression(obj,'x',0);
obj=getnext(obj);
}
or the absence of i in the loop will cause any problems? Excuse my question if naive...I tried and it works I just want to confirm Im not doing something bad for the parser.

Or is it better to go:
decl i=0,obj=Knob1;
while (i<30)
{
setexpression(obj,'x',0);
obj=getnext(obj);
i++;
}

edit: also, it took me longer than it should to understand that the editor is smart enough to know that Knob12 is after Knob9 but the parser needs Knob09 to put Knob12 after it........arghhhhhhhhhhhhhhhhhh......
Can we please at least fix the editor so that Object11 is placed before Object9 (example) to reflect how the parser trule handles the tree order?

Here's what I mean!

fuuuuuuuu.jzml
Yes, it's ok, you don't have to use i inside the for loop.

Concerning the order of objects: I'd suggest putting them into a vector in the desired order and accessing them via an index. Only guessing but I think getnext() doesn't know how your objects are sorted in the editor, I guess they are processed in the order of their creation?
Padding with leading zeros can help a little with that.

Knob001
Knob002
... ... ...
... ... ...
Knob012

There is a slight caveat in that you have to increment the name manually as when (you) Lemur adds another Knob it ignores the "leading zero" convention and will drop in "Knob" and "Knob2" etc.

Conversely, you can prepend.
Joe Soap wrote: Knob001
Knob002
... ... ...
... ... ...
Knob012
Yup, exactly what I did....Took me a while to figure out what was happening though because the objects were scattered in tabs of a container and I wasnt watching the ones that were indeed included in the loop....So I was there standing what the hell Im doing wrong and not all my (at the time visible tab) objects didnt follow the loop. Also, related to my confusion was the fact that "tabs" of a container are really not part of the tree structure as far as the parser is concerned....getnext(object) will move to the next object in a container regardless of the tab it resides in! ;)