LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop

Hi everyone,

 

I am working in a Labview project which has some structures, one of them is a while loop. In this loop I receive a numeric variable (4.25) and then subtract 0.25 until the result will be zero. The issue is that i've tried everything but still i can't do it. So your help will be greatly appreciated.

 

Thanks.

 

 

0 Kudos
Message 1 of 4
(2,745 Views)

You can do this with a shift register, a subtract node, and an equality node. However, be careful with equality, since you're using non-integer values. A test for (a-b)<small_amount will probably be more reliable than a-b=0.

 

Alternatively, subtract your 0.25 each time and check for less than zero. Just be aware this might stop an iteration later than what you want, so you'd need to handle that if so.


GCentral
0 Kudos
Message 2 of 4
(2,733 Views)

Hi pz,

 

and what's the relation to your thread topic? Is it a fault of the while loop?

 

The issue is that i've tried everything but still i can't do it.

What have you tried? What is "everything"?

(If it would be everything you would have found a solution to your problem!)

Because you didn't attach your VI I can only guess: the problem is related to floating point precision! Look up this topic in the forum, you will find a huge amount of related threads!

 

In this loop I receive a numeric variable (4.25) and then subtract 0.25 until the result will be zero

Possible solution:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 4
(2,730 Views)

Show us your code. Otherwise we can only guess what the problem might be.

 

My guess is that you are running into a limitation of the floating point format. Why don't you do everything 100x larger using integers, then divide the result by 100 for a DBL display.

0 Kudos
Message 4 of 4
(2,729 Views)