LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop for loop inside while loop

Solved!
Go to solution

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!

0 Kudos
Message 1 of 10
(4,683 Views)

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

 

 

Learning new things everyday...
0 Kudos
Message 2 of 10
(4,668 Views)

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.

0 Kudos
Message 3 of 10
(4,660 Views)

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.

0 Kudos
Message 4 of 10
(4,654 Views)

Hello altenbach

 

Please check my attached vi.

 

Thanks

0 Kudos
Message 5 of 10
(4,636 Views)

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

 

Learning new things everyday...
0 Kudos
Message 6 of 10
(4,621 Views)

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.

0 Kudos
Message 7 of 10
(4,617 Views)

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

0 Kudos
Message 8 of 10
(4,601 Views)
Solution
Accepted by topic author TayAus1

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). 

3.JPG

When the stop button is selected, it should trigger the stop event as shown below:

4.JPG

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. 

 

5.JPG

 

So when either x or x2 value changes, the code within the event subdiagram shown below will execute. 

7.JPG

 

Warmest regards,

Lennard.C

 

 

Learning new things everyday...
Message 9 of 10
(4,590 Views)

Thanks for your advice.

0 Kudos
Message 10 of 10
(4,569 Views)