From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using OR || in while loop condition

This seems like a pretty simple thing, but maybe I'm missing something in the syntax.

I would like my while loop to be dependent upon two conditions, Here is what I have in the while loop condition field:

 

(Locals.ps_current < .6) || ((Seconds() - Local.StartTime) < 4)

 

Each of these statements work as expected when run on their own, but the OR (II) operator is not functioning as I would expect. The loop only ever exits after the first condition is fulfilled. Is it possible to have a while loop dependent on an OR statement like this?

 

Help?

0 Kudos
Message 1 of 7
(4,414 Views)

What you have is correct.  OR means that only one of the conditions has to be met.  If you want it to exit if both conditions are met then use an AND (&&).

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 7
(4,403 Views)

Thanks jigg, that's good to know, however it is not executing correctly. Only the first condition is evaluated but the second one is ignored. I have tried running each condition on it's own and the while loop exits as expected, but not when they are OR'd. Any ideas?

0 Kudos
Message 3 of 7
(4,401 Views)

That's odd.  I do this all the time.  What if you put parenthesis around the entire statement?

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 7
(4,396 Views)

In addition you could try the AnyOf function:

 

https://zone.ni.com/reference/en-XX/help/370052R-01/tsfundamentals/infotopics/anyof/

 

 

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 5 of 7
(4,395 Views)

Oops... I was thinking of it wrong. I wanted the while loop to stop if either of the conditions were false, which is an AND not an OR. 

 

Thanks for the heads up about the AnyOf function though, that's definitely something I'll use. thanks for your time, sorry!

0 Kudos
Message 6 of 7
(4,391 Views)

AnyOf should work. Alternatively put brakets around the whole boolean logic. Point is that the expression has to evaluate to a boolean value. If one statement returns that, the next parts of the expression are ignored. In your case, the first part already evaluates to a boolean value hence the AND or OR logic is not taken into account.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 7
(4,362 Views)