question for loops (i iterations)

Discuss Lemur and share techniques.
Post Reply
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

question for loops (i iterations)

Post by Softcore »

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:

Code: Select all

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:

Code: Select all

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
(30.96 KiB) Downloaded 92 times
Rolix
Newbie
Posts: 28
Joined: 18 Mar 2013 19:41
Location: Munich

Re: question for loops (i iterations)

Post by Rolix »

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?
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: question for loops (i iterations)

Post by Softcore »

Thanks for the reply.....

As for the order, I think it goes strictly alphabetically and by strictly alphabetically I mean that "Knob2" and "Knob3" are after "Knob12" (aplhabetically speaking). Confirmed by my post example above!
Joe Soap
Regular
Posts: 462
Joined: 07 Jul 2012 15:04

Re: question for loops (i iterations)

Post by Joe Soap »

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.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: question for loops (i iterations)

Post by Softcore »

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! ;)
Post Reply