01-24-2014 12:39 AM
Hi all
Is there a way to stop a for loop inside a while loop? Program will stop executing when the stop button is pressed but I want while loop to keep on running and only the for loop will stop when the condition is met.
Thanks!
Solved! Go to Solution.
01-24-2014 12:50 AM
Hi TayAus1,
I'm not sure what you mean by that. But I can suggest that you can try using the Conditional termination for the for loop. You can read the below for your info:
Configurating LabVIEW For loops to Exit conditionally
http://www.ni.com/white-paper/6285/en/
The for loop in LabVIEW runs in a way that it checks the condition first and it runs the code only if the condition is met. As for While loop, they run the code first before checking of the condition.
Hope it helps
Warmest regards,
Lennard.C
01-24-2014 12:54 AM - edited 01-24-2014 12:55 AM
Show the conditional terminal of the for loop, place the stop terminal inside the FOR loop and wire it to the conditional terminal.
If you needs more specific advice, please show us your code. Thanks.
01-24-2014 12:56 AM
Hello Lennard.C
I already tried using conditional terminal to stop for loop but it didn't stop since it is inside while loop.
I created a file and attached it below.
01-24-2014 01:05 AM
Hello altenbach
Please check my attached vi.
Thanks
01-24-2014 01:11 AM - edited 01-24-2014 01:16 AM
Hi TayAus1,
Thanks for your reply. Can you explain your code? Especially the case structure? If the numeric is 1 you want the for loop to stop running but as for the numeric = 0, it keeps stop running? You want the while loop to run even the for loop stops running? How many time do you want your for loop to run (you specified to run it once)?
While loop executes anything inside the while loop including for loop unless you stop the while loop. For loop will run to check the condition but it will not execute inside the code inside the for loop if the condition has met.
Or perhaps you want to use Events structure whereby it only runs the code upon event source trigger (event-driven programming)?
More info below:
http://www.ni.com/white-paper/3331/en/
http://zone.ni.com/reference/en-XX/help/371361K-01/glang/event_structure/
Warmest regards,
Lennard.C
01-24-2014 01:14 AM
Your FOR loop only does a single iteration and stops no matter what, it will start over a nanosecond later because of the while loop.
Overall, your code makes very, very little sense. Please explain what it should do and how you use it.
01-24-2014 01:44 AM
Hello
What I want to do is "numeric" control can be change either 0 or 1 to decide which case to execute, and when it is 0, "x" control can be changed only once to any numbers to get x*y value. And when "numeric" control is 1, "x 2" control can also be change only once.
Thanks
01-24-2014 01:53 AM - edited 01-24-2014 02:05 AM
Hi TayAus 1,
So you want to run the execution once? Perhaps something like below? The code inside events structure can run only when the events source is triggered. For example, the code within the Numeric only runs when it detects a change in numeric value (just an example).
When the stop button is selected, it should trigger the stop event as shown below:
If you want to create the event source, create the event structure >> right click on the frame and select edit events handled this case... >> this should open the Edit Events.
The example below is that I have set the events source to be the change of value of x and x2.
So when either x or x2 value changes, the code within the event subdiagram shown below will execute.
Warmest regards,
Lennard.C
01-24-2014 02:21 AM
Thanks for your advice.