Jump to content

Vex question : "&&" appears to work like "||" instead during a while loop


sortofsleepy

Recommended Posts

Hey everybody, a bit of a Houdini beginner still and I figured I'd try here for some help since this issue has been gnawing away at me the past couple of days ha.

I am trying to port something from Javascript over to Vex at the moment and have been running into issues. I'm almost got things figured out but am having trouble with what is hopefully the last issue.

This is basically the code I'm trying to make work at the moment.

int count = 0; 
float radius = 0.01;
float growth = 0.01;
float max = 0.5;

while(radius < max && count < 20){
  
    radius += growth;
    count++;
    
}

// do something with radius afterwards

The issue I am finding is that the "&&" operator appears to act like a "||" operator and things are terminating when the "count<20" portion is reached instead of waiting until both statements are done.

In this example, the radius variable will end up only increasing to .21 instead of .5-ish since count will finish first.

Is there something I'm doing wrong here?

Node Details

=====

  • Wrangle is set to guess group type and run over setting is set to "Detail"
  • Not sure if this would help but code above is just from a test node; node I'm trying to write to has 5 points coming into the first slot from a scatter node.

Thank you!

 

Edited by sortofsleepy
Link to comment
Share on other sites

(just in case it helps anyone else)

Not completely sure, but I think the problem you were having, were the extra spaces in your while condition ;)
without brackets, sometimes it does "connect" the operators in unexpected ways.

so

while(radius < max && count < 20){

 

might behave differently than:

while((radius < max) && (count < 20)){

or

while(radius<max && count<20){

(last 2 should behave the same)

Edited by acey195
  • Like 2
Link to comment
Share on other sites

In this case, wouldn't you actually want || ? 

If you have 1 && 1 it will loop, but if one of them changes it will stop - 1 && 0. But with 1 || 0 it will still continue if either one of them is still true, so it will "wait" until both are false, 1 || 1 = true, 1 || 0 = true, 0 || 0 = false.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...