Increment of New For Loop VOP

   2718   5   0
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Hello guys.
In old for loop VOP there was a parameter called step for increment but Anyone knows how to change increment of new for loop in VOPs?
Seems Houdini always tends to increase index by 1!
Thanks in advance.
User Avatar
Staff
6205 posts
Joined: July 2005
Offline
The loop index always increments by one.

a) You could use a while loop and do the increment yourself.
b) You could multiply the index value by your step size inside the loop
c) You could add an extra variable that you feed back that increments by your step size to go along with the base increment.

b & c require dividing your length by step size.
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Really thanks Jeff.
I tried to manipulate index variable but Houdini shows me (Multiple declarations of variable: index_out. (3,5:13)) error!
Edited by Nima - June 2, 2017 18:33:30
User Avatar
Staff
6205 posts
Joined: July 2005
Offline
In attached I multiply the current index by four to get an effective step-by-four.

Attachments:
loopbyfour.hip (81.2 KB)

User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Thank you dear Jeff.
I've looked at the while loop as you said for doing custom increment but it is actually do while loop which is trapped in a if statement.
So haven't we real while loop like:
while(condition == 1){
//do something
}
in VOPs?
Edited by Nima - June 2, 2017 18:44:29
User Avatar
Staff
6205 posts
Joined: July 2005
Offline
How is is that not a real while loop?

if (foo)
{
  do
  {
  } while (foo)
}

is equivalent to

while (foo)
{
}

The only difference is typing, which isn't an issue when the code is auto-generated.

It is hard to express a true while loop in VOPs because your continue condition depends on fed-back wires, while the initial condition can't depend on fed-back wires.

Attached shows that previous example as a while loop.

Attachments:
loopbyfour_while.hip (89.1 KB)

  • Quick Links