10-04-2022 03:01 PM
Hi Everyone,
I want to run while loop with number of iteration its working fine in attached vi. now i want to modify the vi such as if iterations 1 or more iterations are give then it should run with given number of iterations and number of iteration is zero then it should run continuously.. how can i modify it??
thank you in advance
10-04-2022 03:06 PM
Hi new,
@newmemeber123 wrote:
if iterations 1 or more iterations are give then it should run with given number of iterations and number of iteration is zero then it should run continuously.. how can i modify it??
Why is desired iterations an orange DBL?
You seem to have problems to transcript your requirements into (pseudo)code:
STOP := (i >= desired_iteration) AND NOT (desired_iteration == 0)
10-04-2022 03:42 PM - edited 10-04-2022 03:45 PM
Here is a code that does what you want, but the specification is weird because there should never be an infinite loop waiting for a user input with no delay, it saturates the processor.
I added a 10ms delay in case we are in an infinite loop. Here when the input is 0, the "equal" function always returns false, so the only way of stopping the loop is through the stop button.
10-04-2022 03:46 PM
How about this?
10-04-2022 06:52 PM
(Yes, as has been said, your loops needs a wait, your desired iteration needs to be an integer, and never hide the label of terminals)
You need much tighter specifications:
10-05-2022 02:32 AM - edited 10-05-2022 02:33 AM
1, User will not give more than 500 iterations
2, No negative number will be given
3, it should work while running... i added pause and play code in it now.. if i pause running loop and give the iteration it should work only for given iterations it should not run continuously or for previous iteration.
3, im measuring voltage from sensors so it should measure continuously or the code should stop or for given iterations.
im attaching the modified vi as per yours suggestions.. its working for continuously or given number of iterations but its not working if i pause running loop and give iterations and rerun it again.
ow can i modify the code?
thank you for the inputs
10-05-2022 10:53 AM - edited 10-05-2022 11:12 AM
10-05-2022 11:09 AM
See if this can give you some ideas ....
First, try to understand every bit of it, then modify as needed.
Might need a few tweaks, nothing a +1 or -1 in the right place cannot fix. 😄
10-06-2022 07:30 AM - edited 10-06-2022 07:47 AM
thanks, altenbach,
Thank you for such and great example. this is working fine but initially it's on pause pause state(case)
.. i need it initially at play state (running state) the after pressing button it should be pause satate.. i tried to change a code such as making condition false and changing it i or making decrement but im not getting idea how can do it?
thank you
10-06-2022 09:25 AM
You can switch the control to true, select it, and do a menu...edit...make selected values default. Now it will be true when you open the VI.
However, In a more typical program designed for the end users, it makes more sense for a VI to open in the idle state. One it is a built application, it will run when opened anyway, so FALSE is a better default, giving you time to set up the instrument.