LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange behavior of the WHILE loop

Solved!
Go to solution

Dear LabVIEW experts 🙂

 

I would like to ask you for providing me an explanation of behavior of the very simple VI in attachment. This VI contains one WHILE loop with three input parameters FROM, TO and STEP. The RESULT array shows computed values. If we consider input parameters FROM = 0, TO = 1, STEP = 0.1, then RESULT array contains values 0, 0.1, 0.2, ......, 0.9, 1. If we consider input parameters FROM = 1, TO = 2, STEP = 0.1, then RESULT array contains values 1, 1.1, 1.2, ......, 1.8, 1.9. The question is, why the number 2 is missing?  (I was also trying to use different data-types, but without success). Thank you for your thoughts.

 

Juraj

0 Kudos
Message 1 of 3
(2,198 Views)
Solution
Accepted by topic author Jurec

Because you are comparing floating point numbers.

 

For example 0.1 cannot be exactly represented in binary, so repetitve additions will probably not end in an exact integer later.

 

From the three inputs you can calculate the number of values exactly, and use a FOR loop. Don't use convoluted code.... 😉

 

Why don't you simply use ramp pattern?

 

 

0 Kudos
Message 2 of 3
(2,192 Views)

Thanks, ramp pattern is exactly what I was looking for 🙂

0 Kudos
Message 3 of 3
(2,186 Views)