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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Similar code to n=n+1 (n=n+x) with conditional variable to stop

This may be an simple algorithm, but I can't do it.

 

I need to do a VI with an algorithm so similar to n=n+1 , but I need 2 variables, something like n=n+x, and other conditional variable (numerical control).

 

I need to enter the values n and x with a control and after the sustraction of these values but I need to print the value and after repit the process until the conditional value, and impress all the values incluiding the the first n value and the conditional value. And stop the process when the value is equal to the conditional value to get a data.

 

Basically

 

n=n+x

 

n=0

x=2

 

Conditional value (y)

y=10

 

and impress all the values in a data

n=0 (impress)

n=0+2 -->2 (impress)

n=2+2--->4 (impress)

n=4+2---->6 (impress)

n=6+2---->8 (impress)

n=8+2---->10 (impress)

 

And get a data like

 

0

2

4

6

8

10

 

The real problem is that I need enter with numerical controls all values and get the data with the n's first value and the conditional value.

 

If someone can help me, I appreciate it very much.

 

Thanks

0 Kudos
Message 1 of 6
(3,135 Views)

Hi Walter,

 

this sounds like you want to learn LabVIEW! To do so I recommend to take all those free online resources offered by NI (like www.learnni.com ).

 

Your task requires a WHILE loop, a shift register and a comparison node…

 

The next time you ask a question on a programming problem you have you should attach the VI you are currently working on. This way you will get better comments on how to improve your programming skill and style!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(3,128 Views)

Walter_White wrote:

The real problem is that I need enter with numerical controls all values and get the data with the n's first value and the conditional value.

 


It would be a much bigger problem if you didn't have to do this.  This is, by far, the easiest way to do what you're wanting to do.  I'd take Gerd's advice and post what you've tried so far.  With questions that sound like homework problems, people are much less likely to give you the answer and more likely to direct you to it so you learn in the process.  This certainly sounds like a homework problem as it tests your understanding of shift registers, while loops, arrays, and subVIs.

0 Kudos
Message 3 of 6
(3,051 Views)

This is what you are looking for.

 n = n+x

157+ CLDs & 9 CLA Trained
LabVIEW Training resources
0 Kudos
Message 4 of 6
(3,019 Views)

I'd be worried about that loop never stopping if no iteration of n+x is exactly y.  You might want to replace the equals with greater than or equal.

0 Kudos
Message 5 of 6
(3,008 Views)

@ramktamu wrote:

This is what you are looking for.

 n = n+x


  • The stopping problem has already been mentioned.
  • The "first call?" and "select" can be eliminated by initializing the shift register with "n".
  • Unless the "x" and "y" are allowed to vary during execution of the loop (would need very fast fingers and would generate irreproducible results!), these terminals belong before the loop. No need to go to the UI to re-read their value with every iteration of the loop.
  • Typically, the number of iterations can be calculated from the inputs using simple math, so a FOR loop would be much more appropriate and efficient here.

 

Try to simplify according to these comments and re-post. 😄

0 Kudos
Message 6 of 6
(2,979 Views)